cluster.go 1.6 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5
package entity

import "fmt"

//const ClusterDefaultName = "default"
Y
Your Name 已提交
6 7

//Cluster cluster
E
eoLinker API Management 已提交
8
type Cluster struct {
Y
Your Name 已提交
9
	ID    int    `json:"-" yaml:"-"`
Y
Your Name 已提交
10 11
	Name  string `json:"name" yaml:"name"`
	Title string `json:"title" yaml:"title"`
E
eoLinker API Management 已提交
12
}
Y
Your Name 已提交
13 14

//ClusterInfo 集群信息
E
eoLinker API Management 已提交
15
type ClusterInfo struct {
Y
Your Name 已提交
16
	ID    int          `json:"-" yaml:"-"`
E
eoLinker API Management 已提交
17 18 19 20 21 22
	Name  string       `json:"name" yaml:"name"`
	Title string       `json:"title" yaml:"title"`
	Note  string       `json:"note" yaml:"note"`
	DB    ClusterDB    `json:"db" yaml:"db"`
	Redis CLusterRedis `json:"redis" yaml:"redis"`
}
Y
Your Name 已提交
23 24

//ClusterDB cluster db
E
eoLinker API Management 已提交
25 26 27 28 29 30 31 32
type ClusterDB struct {
	Driver   string `json:"driver" yaml:"driver"`
	Host     string `json:"host" yaml:"host"`
	Port     int    `json:"port" yaml:"port"`
	UserName string `json:"userName" yaml:"userName"`
	Password string `json:"password" yaml:"password"`
	Database string `json:"database" yaml:"database"`
}
Y
Your Name 已提交
33 34

//CLusterRedis cluster redis
E
eoLinker API Management 已提交
35 36 37 38 39 40 41 42
type CLusterRedis struct {
	Mode     string `json:"mode" yaml:"mode"`
	Addrs    string `json:"addrs" yaml:"addrs"`
	DbIndex  int    `json:"dbIndex" yaml:"dbIndex"`
	Masters  string `json:"masters" yaml:"masters"`
	Password string `json:"password" yaml:"password"`
}

Y
Your Name 已提交
43
//GetDriver 获取驱动
E
eoLinker API Management 已提交
44 45 46 47
func (c *ClusterDB) GetDriver() string {
	return c.Driver
}

Y
Your Name 已提交
48
//GetSource 获取源字符串
E
eoLinker API Management 已提交
49 50 51 52
func (c *ClusterDB) GetSource() string {
	return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8", c.UserName, c.Password, c.Host, c.Port, c.Database)
}

Y
Your Name 已提交
53
//Cluster 获取cluster
Y
Your Name 已提交
54
func (c *ClusterInfo) Cluster() *Cluster {
E
eoLinker API Management 已提交
55
	return &Cluster{
Y
Your Name 已提交
56
		ID:    c.ID,
Y
Your Name 已提交
57 58
		Name:  c.Name,
		Title: c.Title,
E
eoLinker API Management 已提交
59 60
	}

Y
Your Name 已提交
61
}