update.go 1.2 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4
package balance

import (
	"encoding/json"
黄孟柱 已提交
5 6 7
	"github.com/eolinker/goku-api-gateway/common/general"
	dao_balance_update "github.com/eolinker/goku-api-gateway/server/dao/console-mysql/dao-balance-update"
	entity "github.com/eolinker/goku-api-gateway/server/entity/balance-entity"
E
eoLinker API Management 已提交
8 9 10 11 12
)

func init() {
	general.RegeditLater(Update)
}
Y
Your Name 已提交
13 14

//Update 更新
Y
Your Name 已提交
15
func Update() error {
E
eoLinker API Management 已提交
16

Y
Your Name 已提交
17 18
	l, e := dao_balance_update.GetAllOldVerSion()
	if e != nil {
E
eoLinker API Management 已提交
19 20 21
		return e
	}

Y
Your Name 已提交
22 23 24
	defStaticServiceName := dao_balance_update.GetDefaultServiceStatic()
	for _, e := range l {
		update(e, defStaticServiceName)
E
eoLinker API Management 已提交
25 26 27 28 29 30
	}

	return nil

}

Y
Your Name 已提交
31
func update(e *entity.BalanceInfoEntity, serviceName string) {
E
eoLinker API Management 已提交
32

Y
Your Name 已提交
33
	if e == nil {
E
eoLinker API Management 已提交
34 35 36
		return
	}

Y
Your Name 已提交
37
	param := &Param{
E
eoLinker API Management 已提交
38 39 40 41 42 43 44 45
		Name:          e.Name,
		ServiceName:   serviceName,
		AppName:       "",
		Static:        "",
		StaticCluster: "",
		Desc:          e.Desc,
	}

Y
Your Name 已提交
46
	info, err := e.Decode()
E
eoLinker API Management 已提交
47

Y
Your Name 已提交
48
	if err != nil {
E
eoLinker API Management 已提交
49 50 51
		return
	}

Y
Your Name 已提交
52
	if info.Default != nil {
E
eoLinker API Management 已提交
53 54 55

		param.Static = info.Default.ServersConfigOrg
	}
Y
Your Name 已提交
56 57 58
	if info.Cluster != nil {
		cluster := make(map[string]string)
		for clusterName, server := range info.Cluster {
E
eoLinker API Management 已提交
59 60 61 62
			cluster[clusterName] = server.ServersConfigOrg

		}

Y
Your Name 已提交
63
		data, err := json.Marshal(cluster)
E
eoLinker API Management 已提交
64

Y
Your Name 已提交
65
		if err == nil {
E
eoLinker API Management 已提交
66 67 68 69 70 71 72

			param.StaticCluster = string(data)
		}
	}

	Save(param)

Y
Your Name 已提交
73
}