sqlite的api,便于内部使用
liuxiaolong
2020-09-21 5c9ba220ac6640d9d1b1da97caa7aa3419441be3
dicApi.go
@@ -2,15 +2,29 @@
import (
   "encoding/json"
   "fmt"
   "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 := BASIC_URL + DATA_URL_PREFIX + "/dictionary/findByType"
   url := api.getBasicUrl() + DATA_URL_PREFIX + "/dictionary/findByType"
   client := NewClient()
   paramMap := make(map[string]string)
   paramMap["type"] = dicType
@@ -20,8 +34,25 @@
   }
   var res Result
   if err = json.Unmarshal(respBody, &res); err != nil {
      fmt.Println(err)
      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
}