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

import "fmt"

//const ClusterDefaultName = "default"
type Cluster struct {
Y
Your Name 已提交
7 8 9
	Id    int    `json:"-" yaml:"-"`
	Name  string `json:"name" yaml:"name"`
	Title string `json:"title" yaml:"title"`
E
eoLinker API Management 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
}
type ClusterInfo struct {
	Id    int          `json:"-" yaml:"-"`
	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"`
}
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"`
}
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"`
}

func (c *ClusterDB) GetDriver() string {
	return c.Driver
}

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 已提交
43
func (c *ClusterInfo) Cluster() *Cluster {
E
eoLinker API Management 已提交
44
	return &Cluster{
Y
Your Name 已提交
45 46 47
		Id:    c.Id,
		Name:  c.Name,
		Title: c.Title,
E
eoLinker API Management 已提交
48 49
	}

Y
Your Name 已提交
50
}