From b5aadb41f6cfdca16e7fd4b3637d14c412ae1e97 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期一, 28 十月 2019 18:38:13 +0800
Subject: [PATCH] add func

---
 dicApi.go |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/dicApi.go b/dicApi.go
index 0bdd17d..bd0edda 100644
--- a/dicApi.go
+++ b/dicApi.go
@@ -3,14 +3,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
@@ -25,3 +40,20 @@
 	}
 	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 {
+		fmt.Println(err)
+		return false,nil
+	}
+	return res.Success,res.Data
+}
\ No newline at end of file

--
Gitblit v1.8.0