sqlite的api,便于内部使用
liuxiaolong
2020-06-29 48f75270f4e17f0a5cf4c4df32ca570cf2ee789a
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
package dbapi
 
import (
    "encoding/json"
    "strconv"
)
 
type DicApi struct {
    Ip string
    Port int
}
 
func (api DicApi) getBasicUrl() string {
    if api.Ip == "" {
        return BASIC_URL
    }
    if api.Ip == "" {
        api.Ip = DEFAULT_IP
    }
    if api.Port == 0 {
        api.Port = DEFAULT_PORT
    }
    return "http://"+api.Ip+":"+strconv.Itoa(api.Port)
}
 
func (api DicApi) FindByType(dicType string) (bool,interface{}) {
    url := api.getBasicUrl() + DATA_URL_PREFIX + "/dictionary/findByType"
    client := NewClient()
    paramMap := make(map[string]string)
    paramMap["type"] = dicType
    respBody, err := client.DoGetRequest(url, paramMap, nil)
    if err !=nil {
        return false,nil
    }
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        logPrint(err)
        return false,nil
    }
    return res.Success,res.Data
}
 
func (api DicApi) FindByParentId(parentId string) (bool,interface{}){
    url := api.getBasicUrl() + DATA_URL_PREFIX + "/dictionary/findByParentId"
    client := NewClient()
    paramMap := make(map[string]string)
    paramMap["parentId"] = parentId
    respBody, err := client.DoGetRequest(url, paramMap, nil)
    if err !=nil {
        return false,nil
    }
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        logPrint(err)
        return false,nil
    }
    return res.Success,res.Data
}