Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
|
58449325cc | |
|
7b95c9d688 | |
|
4464edc1fd | |
|
475201a1bd | |
|
ea5688693d | |
|
50ff4f1cf8 | |
|
0b9b305eac | |
|
56bbfcfa80 |
|
@ -103,7 +103,7 @@ func NewConfigClient(nc nacos_client.INacosClient) (*ConfigClient, error) {
|
|||
LogRollingConfig: clientConfig.LogRollingConfig,
|
||||
LogDir: clientConfig.LogDir,
|
||||
CustomLogger: clientConfig.CustomLogger,
|
||||
LogStdout: clientConfig.LogStdout,
|
||||
LogStdout: clientConfig.AppendToStdout,
|
||||
}
|
||||
err = logger.InitLogger(loggerConfig)
|
||||
if err != nil {
|
||||
|
|
|
@ -18,6 +18,7 @@ package config_client
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
@ -31,7 +32,6 @@ import (
|
|||
"github.com/nacos-group/nacos-sdk-go/mock"
|
||||
"github.com/nacos-group/nacos-sdk-go/util"
|
||||
"github.com/nacos-group/nacos-sdk-go/vo"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -39,17 +39,9 @@ var goVersion = runtime.Version()
|
|||
|
||||
var clientConfigTest = constant.ClientConfig{
|
||||
TimeoutMs: 10000,
|
||||
ListenInterval: 20000,
|
||||
BeatInterval: 10000,
|
||||
}
|
||||
|
||||
var clientConfigTestWithTenant = constant.ClientConfig{
|
||||
TimeoutMs: 10000,
|
||||
ListenInterval: 20000,
|
||||
BeatInterval: 10000,
|
||||
NamespaceId: "tenant",
|
||||
}
|
||||
|
||||
var serverConfigTest = constant.ServerConfig{
|
||||
ContextPath: "/nacos",
|
||||
Port: 80,
|
||||
|
@ -71,9 +63,6 @@ var (
|
|||
configNoChangeKey = goVersion + "ConfigNoChange"
|
||||
multipleClientsKey = goVersion + "MultipleClients"
|
||||
multipleClientsMultipleConfigsKey = goVersion + "MultipleClientsMultipleConfig"
|
||||
cancelOneKey = goVersion + "CancelOne"
|
||||
cancelOne1Key = goVersion + "CancelOne1"
|
||||
cancelListenConfigKey = goVersion + "cancel_listen_config"
|
||||
specialSymbolKey = goVersion + "special_symbol"
|
||||
)
|
||||
|
||||
|
@ -472,33 +461,33 @@ type mockLogger struct {
|
|||
}
|
||||
|
||||
func (m mockLogger) Info(args ...interface{}) {
|
||||
logrus.Info(args...)
|
||||
fmt.Println(args...)
|
||||
}
|
||||
|
||||
func (m mockLogger) Warn(args ...interface{}) {
|
||||
logrus.Info(args...)
|
||||
fmt.Println(args...)
|
||||
}
|
||||
|
||||
func (m mockLogger) Error(args ...interface{}) {
|
||||
logrus.Info(args...)
|
||||
fmt.Println(args...)
|
||||
}
|
||||
|
||||
func (m mockLogger) Debug(args ...interface{}) {
|
||||
logrus.Info(args...)
|
||||
fmt.Println(args...)
|
||||
}
|
||||
|
||||
func (m mockLogger) Infof(format string, args ...interface{}) {
|
||||
logrus.Infof(format, args...)
|
||||
fmt.Println(fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
func (m mockLogger) Warnf(format string, args ...interface{}) {
|
||||
logrus.Warnf(format, args...)
|
||||
fmt.Println(fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
func (m mockLogger) Errorf(format string, args ...interface{}) {
|
||||
logrus.Errorf(format, args...)
|
||||
fmt.Println(fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
func (m mockLogger) Debugf(format string, args ...interface{}) {
|
||||
logrus.Debugf("implement me")
|
||||
fmt.Println("implement me")
|
||||
}
|
||||
|
|
|
@ -57,8 +57,8 @@ func (cp *ConfigProxy) GetConfigProxy(param vo.ConfigParam, tenant, accessKey, s
|
|||
}
|
||||
|
||||
var headers = map[string]string{}
|
||||
headers["accessKey"] = accessKey
|
||||
headers["secretKey"] = secretKey
|
||||
headers[constant.KEY_ACCESS_KEY] = accessKey
|
||||
headers[constant.KEY_SECRET_KEY] = secretKey
|
||||
|
||||
result, err := cp.nacosServer.ReqConfigApi(constant.CONFIG_PATH, params, headers, http.MethodGet, cp.clientConfig.TimeoutMs)
|
||||
return result, err
|
||||
|
|
|
@ -70,8 +70,8 @@ func (br *BeatReactor) AddBeatInfo(serviceName string, beatInfo *model.BeatInfo)
|
|||
defer br.mux.Unlock()
|
||||
br.mux.Lock()
|
||||
if data, ok := br.beatMap.Get(k); ok {
|
||||
beatInfo = data.(*model.BeatInfo)
|
||||
atomic.StoreInt32(&beatInfo.State, int32(model.StateShutdown))
|
||||
oldBeatInfo := data.(*model.BeatInfo)
|
||||
atomic.StoreInt32(&oldBeatInfo.State, int32(model.StateShutdown))
|
||||
br.beatMap.Remove(k)
|
||||
}
|
||||
br.beatMap.Set(k, beatInfo)
|
||||
|
@ -111,8 +111,7 @@ func (br *BeatReactor) sendInstanceBeat(k string, beatInfo *model.BeatInfo) {
|
|||
if err != nil {
|
||||
logger.Errorf("beat to server return error:%+v", err)
|
||||
br.beatThreadSemaphore.Release(1)
|
||||
t := time.NewTimer(beatInfo.Period)
|
||||
<-t.C
|
||||
time.Sleep(beatInfo.Period)
|
||||
continue
|
||||
}
|
||||
if beatInterval > 0 {
|
||||
|
@ -122,7 +121,6 @@ func (br *BeatReactor) sendInstanceBeat(k string, beatInfo *model.BeatInfo) {
|
|||
br.beatRecordMap.Set(k, util.CurrentMillis())
|
||||
br.beatThreadSemaphore.Release(1)
|
||||
|
||||
t := time.NewTimer(beatInfo.Period)
|
||||
<-t.C
|
||||
time.Sleep(beatInfo.Period)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,27 +119,27 @@ func (hr *HostReactor) GetServiceInfo(serviceName string, clusters string) (mode
|
|||
return cacheService.(model.Service), nil
|
||||
}
|
||||
|
||||
func (hr *HostReactor) GetAllServiceInfo(nameSpace, groupName string, pageNo, pageSize uint32) model.ServiceList {
|
||||
func (hr *HostReactor) GetAllServiceInfo(nameSpace, groupName string, pageNo, pageSize uint32) (model.ServiceList, error) {
|
||||
data := model.ServiceList{}
|
||||
result, err := hr.serviceProxy.GetAllServiceInfoList(nameSpace, groupName, pageNo, pageSize)
|
||||
if err != nil {
|
||||
logger.Errorf("GetAllServiceInfoList return error!nameSpace:%s groupName:%s pageNo:%d, pageSize:%d err:%+v",
|
||||
nameSpace, groupName, pageNo, pageSize, err)
|
||||
return data
|
||||
return data, err
|
||||
}
|
||||
if result == "" {
|
||||
logger.Errorf("GetAllServiceInfoList result is empty!nameSpace:%s groupName:%s pageNo:%d, pageSize:%d",
|
||||
logger.Warnf("GetAllServiceInfoList result is empty!nameSpace:%s groupName:%s pageNo:%d, pageSize:%d",
|
||||
nameSpace, groupName, pageNo, pageSize)
|
||||
return data
|
||||
return data, nil
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(result), &data)
|
||||
if err != nil {
|
||||
logger.Errorf("GetAllServiceInfoList result json.Unmarshal error!nameSpace:%s groupName:%s pageNo:%d, pageSize:%d",
|
||||
nameSpace, groupName, pageNo, pageSize)
|
||||
return data
|
||||
return data, err
|
||||
}
|
||||
return data
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (hr *HostReactor) updateServiceNow(serviceName, clusters string) {
|
||||
|
|
|
@ -74,7 +74,7 @@ func NewNamingClient(nc nacos_client.INacosClient) (NamingClient, error) {
|
|||
LogRollingConfig: clientConfig.LogRollingConfig,
|
||||
LogDir: clientConfig.LogDir,
|
||||
CustomLogger: clientConfig.CustomLogger,
|
||||
LogStdout: clientConfig.LogStdout,
|
||||
LogStdout: clientConfig.AppendToStdout,
|
||||
}
|
||||
err = logger.InitLogger(loggerConfig)
|
||||
if err != nil {
|
||||
|
@ -210,8 +210,7 @@ func (sc *NamingClient) GetAllServicesInfo(param vo.GetAllServiceInfoParam) (mod
|
|||
if param.PageSize == 0 {
|
||||
param.PageSize = 10
|
||||
}
|
||||
services := sc.hostReactor.GetAllServiceInfo(param.NameSpace, param.GroupName, param.PageNo, param.PageSize)
|
||||
return services, nil
|
||||
return sc.hostReactor.GetAllServiceInfo(param.NameSpace, param.GroupName, param.PageNo, param.PageSize)
|
||||
}
|
||||
|
||||
// SelectAllInstances select all instances
|
||||
|
@ -284,28 +283,27 @@ func (sc *NamingClient) selectOneHealthyInstances(service model.Service) (*model
|
|||
return nil, errors.New("healthy instance list is empty!")
|
||||
}
|
||||
|
||||
chooser := newChooser(result)
|
||||
instance := chooser.pick()
|
||||
instance := newChooser(result).pick()
|
||||
return &instance, nil
|
||||
}
|
||||
|
||||
type instance []model.Instance
|
||||
type instances []model.Instance
|
||||
|
||||
func (a instance) Len() int {
|
||||
func (a instances) Len() int {
|
||||
return len(a)
|
||||
}
|
||||
|
||||
func (a instance) Swap(i, j int) {
|
||||
func (a instances) Swap(i, j int) {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
}
|
||||
|
||||
func (a instance) Less(i, j int) bool {
|
||||
func (a instances) Less(i, j int) bool {
|
||||
return a[i].Weight < a[j].Weight
|
||||
}
|
||||
|
||||
// NewChooser initializes a new Chooser for picking from the provided Choices.
|
||||
func newChooser(instances []model.Instance) Chooser {
|
||||
sort.Sort(instance(instances))
|
||||
func newChooser(instances instances) Chooser {
|
||||
sort.Sort(instances)
|
||||
totals := make([]int, len(instances))
|
||||
runningTotal := 0
|
||||
for i, c := range instances {
|
||||
|
@ -321,7 +319,7 @@ func (chs Chooser) pick() model.Instance {
|
|||
return chs.data[i]
|
||||
}
|
||||
|
||||
//Subscribe subscibe service
|
||||
// Subscribe subscribe service
|
||||
func (sc *NamingClient) Subscribe(param *vo.SubscribeParam) error {
|
||||
if len(param.GroupName) == 0 {
|
||||
param.GroupName = constant.DEFAULT_GROUP
|
||||
|
@ -337,7 +335,7 @@ func (sc *NamingClient) Subscribe(param *vo.SubscribeParam) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !sc.hostReactor.serviceProxy.clientConfig.NotLoadCacheAtStart {
|
||||
if sc.hostReactor.serviceProxy.clientConfig.NotLoadCacheAtStart {
|
||||
sc.subCallback.ServiceChanged(&svc)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -66,7 +66,7 @@ func (proxy *NamingProxy) RegisterInstance(serviceName string, groupName string,
|
|||
params["healthy"] = strconv.FormatBool(instance.Healthy)
|
||||
params["metadata"] = util.ToJsonString(instance.Metadata)
|
||||
params["ephemeral"] = strconv.FormatBool(instance.Ephemeral)
|
||||
return proxy.nacosServer.ReqApi(constant.SERVICE_PATH, params, http.MethodPost)
|
||||
return proxy.nacosServer.ReqApi(constant.SERVICE_PATH, params, http.MethodPost, proxy.getSecurityMap())
|
||||
}
|
||||
|
||||
func (proxy *NamingProxy) DeregisterInstance(serviceName string, ip string, port uint64, clusterName string, ephemeral bool) (string, error) {
|
||||
|
@ -79,7 +79,7 @@ func (proxy *NamingProxy) DeregisterInstance(serviceName string, ip string, port
|
|||
params["ip"] = ip
|
||||
params["port"] = strconv.Itoa(int(port))
|
||||
params["ephemeral"] = strconv.FormatBool(ephemeral)
|
||||
return proxy.nacosServer.ReqApi(constant.SERVICE_PATH, params, http.MethodDelete)
|
||||
return proxy.nacosServer.ReqApi(constant.SERVICE_PATH, params, http.MethodDelete, proxy.getSecurityMap())
|
||||
}
|
||||
|
||||
func (proxy *NamingProxy) UpdateInstance(serviceName string, ip string, port uint64, clusterName string, ephemeral bool, weight float64, enable bool, metadata map[string]string) (string, error) {
|
||||
|
@ -95,7 +95,7 @@ func (proxy *NamingProxy) UpdateInstance(serviceName string, ip string, port uin
|
|||
params["weight"] = strconv.FormatFloat(weight, 'f', -1, 64)
|
||||
params["enable"] = strconv.FormatBool(enable)
|
||||
params["metadata"] = util.ToJsonString(metadata)
|
||||
return proxy.nacosServer.ReqApi(constant.SERVICE_PATH, params, http.MethodPut)
|
||||
return proxy.nacosServer.ReqApi(constant.SERVICE_PATH, params, http.MethodPut, proxy.getSecurityMap())
|
||||
}
|
||||
|
||||
func (proxy *NamingProxy) SendBeat(info *model.BeatInfo) (int64, error) {
|
||||
|
@ -107,7 +107,7 @@ func (proxy *NamingProxy) SendBeat(info *model.BeatInfo) (int64, error) {
|
|||
params["serviceName"] = info.ServiceName
|
||||
params["beat"] = util.ToJsonString(info)
|
||||
api := constant.SERVICE_BASE_PATH + "/instance/beat"
|
||||
result, err := proxy.nacosServer.ReqApi(api, params, http.MethodPut)
|
||||
result, err := proxy.nacosServer.ReqApi(api, params, http.MethodPut, proxy.getSecurityMap())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func (proxy *NamingProxy) GetServiceList(pageNo int, pageSize int, groupName str
|
|||
}
|
||||
|
||||
api := constant.SERVICE_BASE_PATH + "/service/list"
|
||||
result, err := proxy.nacosServer.ReqApi(api, params, http.MethodGet)
|
||||
result, err := proxy.nacosServer.ReqApi(api, params, http.MethodGet, proxy.getSecurityMap())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ func (proxy *NamingProxy) GetServiceList(pageNo int, pageSize int, groupName str
|
|||
|
||||
func (proxy *NamingProxy) ServerHealthy() bool {
|
||||
api := constant.SERVICE_BASE_PATH + "/operator/metrics"
|
||||
result, err := proxy.nacosServer.ReqApi(api, map[string]string{}, http.MethodGet)
|
||||
result, err := proxy.nacosServer.ReqApi(api, map[string]string{}, http.MethodGet, proxy.getSecurityMap())
|
||||
if err != nil {
|
||||
logger.Errorf("namespaceId:[%s] sending server healthy failed!,result:%s error:%+v", proxy.clientConfig.NamespaceId, result, err)
|
||||
return false
|
||||
|
@ -191,7 +191,7 @@ func (proxy *NamingProxy) QueryList(serviceName string, clusters string, udpPort
|
|||
param["healthyOnly"] = strconv.FormatBool(healthyOnly)
|
||||
param["clientIP"] = util.LocalIP()
|
||||
api := constant.SERVICE_PATH + "/list"
|
||||
return proxy.nacosServer.ReqApi(api, param, http.MethodGet)
|
||||
return proxy.nacosServer.ReqApi(api, param, http.MethodGet, proxy.getSecurityMap())
|
||||
}
|
||||
|
||||
func (proxy *NamingProxy) GetAllServiceInfoList(namespace, groupName string, pageNo, pageSize uint32) (string, error) {
|
||||
|
@ -201,5 +201,14 @@ func (proxy *NamingProxy) GetAllServiceInfoList(namespace, groupName string, pag
|
|||
param["pageNo"] = strconv.Itoa(int(pageNo))
|
||||
param["pageSize"] = strconv.Itoa(int(pageSize))
|
||||
api := constant.SERVICE_INFO_PATH + "/list"
|
||||
return proxy.nacosServer.ReqApi(api, param, http.MethodGet)
|
||||
return proxy.nacosServer.ReqApi(api, param, http.MethodGet, proxy.getSecurityMap())
|
||||
}
|
||||
|
||||
func (proxy *NamingProxy) getSecurityMap() map[string]string {
|
||||
result := make(map[string]string, 2)
|
||||
if len(proxy.clientConfig.AccessKey) != 0 && len(proxy.clientConfig.SecretKey) != 0 {
|
||||
result[constant.KEY_ACCESS_KEY] = proxy.clientConfig.AccessKey
|
||||
result[constant.KEY_SECRET_KEY] = proxy.clientConfig.SecretKey
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -184,6 +184,6 @@ func WithLogRollingConfig(rollingConfig *lumberjack.Logger) ClientOption {
|
|||
// WithLogStdout ...
|
||||
func WithLogStdout(logStdout bool) ClientOption {
|
||||
return func(config *ClientConfig) {
|
||||
config.LogStdout = logStdout
|
||||
config.AppendToStdout = logStdout
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,5 +52,5 @@ type ClientConfig struct {
|
|||
ContextPath string // the nacos server contextpath
|
||||
LogRollingConfig *lumberjack.Logger // the log rolling config
|
||||
CustomLogger logger.Logger // the custom log interface ,With a custom Logger (nacos sdk will not provide log cutting and archiving capabilities)
|
||||
LogStdout bool // the stdout redirect for log, default is false
|
||||
AppendToStdout bool // append log to stdout
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ const (
|
|||
KEY_BEAT = "beat"
|
||||
KEY_DOM = "dom"
|
||||
DEFAULT_CONTEXT_PATH = "/nacos"
|
||||
CLIENT_VERSION = "Nacos-Go-Client:v1.0.1"
|
||||
CLIENT_VERSION = "Nacos-Go-Client:v1.1.6"
|
||||
REQUEST_DOMAIN_RETRY_TIME = 3
|
||||
SERVICE_INFO_SPLITER = "@@"
|
||||
CONFIG_INFO_SPLITER = "@@"
|
||||
|
|
|
@ -132,14 +132,19 @@ func (server *NacosServer) callConfigServer(api string, params map[string]string
|
|||
}
|
||||
}
|
||||
|
||||
func (server *NacosServer) callServer(api string, params map[string]string, method string, curServer string, contextPath string) (result string, err error) {
|
||||
func (server *NacosServer) callServer(api string, params map[string]string, header map[string]string, method string, curServer string, contextPath string) (result string, err error) {
|
||||
if contextPath == "" {
|
||||
contextPath = constant.WEB_CONTEXT
|
||||
}
|
||||
|
||||
url := curServer + contextPath + api
|
||||
|
||||
headers := map[string][]string{}
|
||||
headers := make(map[string][]string, len(header))
|
||||
for k, v := range header {
|
||||
if k != constant.KEY_SECRET_KEY {
|
||||
headers[k] = []string{v}
|
||||
}
|
||||
}
|
||||
headers["Client-Version"] = []string{constant.CLIENT_VERSION}
|
||||
headers["User-Agent"] = []string{constant.CLIENT_VERSION}
|
||||
//headers["Accept-Encoding"] = []string{"gzip,deflate,sdch"}
|
||||
|
@ -209,7 +214,7 @@ func (server *NacosServer) ReqConfigApi(api string, params map[string]string, he
|
|||
}
|
||||
}
|
||||
|
||||
func (server *NacosServer) ReqApi(api string, params map[string]string, method string) (string, error) {
|
||||
func (server *NacosServer) ReqApi(api string, params map[string]string, method string, security map[string]string) (string, error) {
|
||||
srvs := server.serverList
|
||||
if srvs == nil || len(srvs) == 0 {
|
||||
return "", errors.New("server list is empty")
|
||||
|
@ -219,25 +224,25 @@ func (server *NacosServer) ReqApi(api string, params map[string]string, method s
|
|||
err error
|
||||
)
|
||||
injectSecurityInfo(server, params)
|
||||
|
||||
signHeader := getSignHeadersForNaming(params, security)
|
||||
//only one server,retry request when error
|
||||
if len(srvs) == 1 {
|
||||
for i := 0; i < constant.REQUEST_DOMAIN_RETRY_TIME; i++ {
|
||||
result, err = server.callServer(api, params, method, getAddress(srvs[0]), srvs[0].ContextPath)
|
||||
result, err = server.callServer(api, params, signHeader, method, getAddress(srvs[0]), srvs[0].ContextPath)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
logger.Errorf("api<%s>,method:<%s>, params:<%s>, call domain error:<%+v> , result:<%s>", api, method, util.ToJsonString(params), err, result)
|
||||
logger.Errorf("api<%s>,method:<%s>, params:<%s>, header:<%s>, call domain error:<%+v> , result:<%s>", api, method, util.ToJsonString(params), util.ToJsonString(signHeader), err, result)
|
||||
}
|
||||
} else {
|
||||
index := rand.Intn(len(srvs))
|
||||
for i := 1; i <= len(srvs); i++ {
|
||||
curServer := srvs[index]
|
||||
result, err = server.callServer(api, params, method, getAddress(curServer), curServer.ContextPath)
|
||||
result, err = server.callServer(api, params, signHeader, method, getAddress(curServer), curServer.ContextPath)
|
||||
if err == nil {
|
||||
return result, nil
|
||||
}
|
||||
logger.Errorf("api<%s>,method:<%s>, params:<%s>, call domain error:<%+v> , result:<%s>", api, method, util.ToJsonString(params), err, result)
|
||||
logger.Errorf("api<%s>,method:<%s>, params:<%s>, header:<%s>, call domain error:<%+v> , result:<%s>", api, method, util.ToJsonString(params), util.ToJsonString(signHeader), err, result)
|
||||
index = (index + i) % len(srvs)
|
||||
}
|
||||
}
|
||||
|
@ -348,6 +353,31 @@ func getSignHeaders(params map[string]string, newHeaders map[string]string) map[
|
|||
return headers
|
||||
}
|
||||
|
||||
func getSignHeadersForNaming(params map[string]string, newHeaders map[string]string) map[string]string {
|
||||
accessKey, containAk := newHeaders[constant.KEY_ACCESS_KEY]
|
||||
secretKey, containSk := newHeaders[constant.KEY_SECRET_KEY]
|
||||
result := map[string]string{}
|
||||
if !containAk || !containSk {
|
||||
return result
|
||||
}
|
||||
var signData string
|
||||
timeStamp := strconv.FormatInt(time.Now().UnixNano()/1e6, 10)
|
||||
if serviceName, ok := params["serviceName"]; ok {
|
||||
if groupName, containGroup := params["groupName"]; strings.Contains(serviceName, constant.SERVICE_INFO_SPLITER) ||
|
||||
!containGroup {
|
||||
signData = timeStamp + constant.SERVICE_INFO_SPLITER + serviceName
|
||||
} else {
|
||||
signData = timeStamp + constant.SERVICE_INFO_SPLITER + util.GetGroupName(serviceName, groupName)
|
||||
}
|
||||
} else {
|
||||
signData = timeStamp
|
||||
}
|
||||
result["signature"] = signWithhmacSHA1Encrypt(signData, secretKey)
|
||||
result["ak"] = accessKey
|
||||
result["data"] = signData
|
||||
return result
|
||||
}
|
||||
|
||||
func signWithhmacSHA1Encrypt(encryptText, encryptKey string) string {
|
||||
//hmac ,use sha1
|
||||
key := []byte(encryptKey)
|
||||
|
|
|
@ -48,7 +48,7 @@ func main() {
|
|||
LogDir: "/tmp/nacos/log",
|
||||
CacheDir: "/tmp/nacos/cache",
|
||||
LogLevel: "debug",
|
||||
LogStdout: true,
|
||||
AppendToStdout: true,
|
||||
}
|
||||
//or a more graceful way to create ClientConfig
|
||||
_ = *constant.NewClientConfig(
|
||||
|
|
|
@ -48,7 +48,7 @@ func main() {
|
|||
CacheDir: "/tmp/nacos/cache",
|
||||
LogRollingConfig: &lumberjack.Logger{MaxSize: 10},
|
||||
LogLevel: "debug",
|
||||
LogStdout: true,
|
||||
AppendToStdout: true,
|
||||
}
|
||||
//or a more graceful way to create ClientConfig
|
||||
_ = *constant.NewClientConfig(
|
||||
|
|
3
go.mod
3
go.mod
|
@ -1,6 +1,6 @@
|
|||
module github.com/nacos-group/nacos-sdk-go
|
||||
|
||||
go 1.12
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18
|
||||
|
@ -9,7 +9,6 @@ require (
|
|||
github.com/golang/mock v1.3.1
|
||||
github.com/json-iterator/go v1.1.6 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/stretchr/testify v1.5.1
|
||||
go.uber.org/zap v1.15.0
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58
|
||||
|
|
5
go.sum
5
go.sum
|
@ -38,14 +38,11 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
|
|||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
|
@ -70,8 +67,6 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEha
|
|||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
|
|
|
@ -16,8 +16,12 @@
|
|||
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type ConfigItem struct {
|
||||
Id string `param:"id"`
|
||||
Id json.Number `param:"id"`
|
||||
DataId string `param:"dataId"`
|
||||
Group string `param:"group"`
|
||||
Content string `param:"content"`
|
||||
|
|
|
@ -23,6 +23,10 @@ import (
|
|||
)
|
||||
|
||||
func Md5(content string) (md string) {
|
||||
if content == "" {
|
||||
return
|
||||
}
|
||||
|
||||
h := md5.New()
|
||||
_, _ = io.WriteString(h, content)
|
||||
md = fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
|
|
@ -25,4 +25,7 @@ import (
|
|||
func TestMd5(t *testing.T) {
|
||||
md5 := Md5("demo")
|
||||
assert.Equal(t, "fe01ce2a7fbac8fafaed7c982a04e229", md5)
|
||||
|
||||
md5 = Md5("")
|
||||
assert.Equal(t, "", md5)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue