From 00b8ac80b4f5689fdfe1fb39a0f2558735bfa39b Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期五, 18 十二月 2020 14:44:37 +0800
Subject: [PATCH] fix url

---
 dicApi.go |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/dicApi.go b/dicApi.go
index 0a2e455..8b697d8 100644
--- a/dicApi.go
+++ b/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,14 +34,14 @@
 	}
 	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 := BASIC_URL + DATA_URL_PREFIX + "/dictionary/findByParentId"
+	url := api.getBasicUrl() + DATA_URL_PREFIX + "/dictionary/findByParentId"
 	client := NewClient()
 	paramMap := make(map[string]string)
 	paramMap["parentId"] = parentId
@@ -37,7 +51,7 @@
 	}
 	var res Result
 	if err = json.Unmarshal(respBody, &res); err != nil {
-		fmt.Println(err)
+		logPrint(err)
 		return false,nil
 	}
 	return res.Success,res.Data

--
Gitblit v1.8.0