liuxiaolong
2021-08-31 87d340b8b52acffcf6c11ddf78a5df5cb24d7e04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package bhomedbapi
 
import (
    "basic.com/valib/c_bhomebus.git/proto/source/bhome_msg"
    "errors"
    "fmt"
    "strconv"
)
 
type Client interface {
    //GET
    DoGetRequest(url string, params map[string]string, headers map[string]string) ([]byte, error)
    //POST
    DoPostRequest(url string, contentType string, body map[string]interface{}, params map[string]string, headers map[string]string) ([]byte, error)
    //PUT
    DoPutRequest(url string, contentType string, body map[string]interface{}, headers map[string]string) ([]byte, error)
    //DELETE
    DoDeleteRequest(url string, contentType string, body map[string]interface{}, headers map[string]string) ([]byte, error)
}
 
var BASIC_URL            = "http://127.0.0.1:8001"
 
var DEFAULT_IP             = "127.0.0.1"
var DEFAULT_PORT         = 8001
 
const (
    DATA_URL_PREFIX      = "/data/api-v"
    CONTENT_TYPE_FORM    = "application/x-www-form-urlencoded"
    CONTENT_TYPE_MULFORM = "multipart/form-data"
    CONTENT_TYPE_JSON    = "application/json"
)
 
var logPrint = func(i ...interface{}) {
    fmt.Println(i...)
}
//初始化dbserver的地址和端口
func Init(ip string,port int){
    BASIC_URL = "http://"+ ip + ":" + strconv.Itoa(port)
}
 
func InitLog(fn func(i ...interface{})) {
    if fn != nil {
        logPrint = fn
    }
}
 
var getNetNode = func(topic string) []*bhome_msg.MsgQueryTopicReply_BHNodeAddress{
    return nil
}
 
func InitGetNetNode(fn func(name string)[]*bhome_msg.MsgQueryTopicReply_BHNodeAddress) {
    //if fn != nil {
    //    getNetNode = fn
    //}
}
 
var busReq = func(req *bhome_msg.MsgRequestTopic,dest []*bhome_msg.MsgQueryTopicReply_BHNodeAddress) ([]byte, error) {
    return nil, errors.New("please init InitDoReq first")
}
 
func InitDoReq(fn func(*bhome_msg.MsgRequestTopic, []*bhome_msg.MsgQueryTopicReply_BHNodeAddress) ([]byte, error)) {
    if fn != nil {
        busReq = fn
    }
}
 
func url2Topic(serviceName string, url string) string {
    return url
}