gmvc配置管理开发

This commit is contained in:
John
2017-12-19 17:33:12 +08:00
parent ef59098989
commit 03109055c1
5 changed files with 29 additions and 13 deletions

View File

@ -136,6 +136,7 @@ func NewByGroup(groupName string) (Link, error) {
if len(masterList) < 1 {
return nil, errors.New("at least one master node configuration's need to make sense")
}
fmt.Println(masterList)
masterNode := getConfigNodeByPriority(&masterList)
var slaveNode *ConfigNode
if len(slaveList) > 0 {

View File

@ -11,8 +11,8 @@ import (
// 框架基类所有的基于gf框架的类对象都继承于此以便使用框架的一些封装的核心组件
type Base struct {
Db gdb.Link
Config *gconfig.Config
Db gdb.Link // 数据库操作对象
Config *gconfig.Config // 配置管理对象
}
// 基类初始化,如若需要自定义初始化内置核心对象组件,可在继承子类中覆盖此方法

View File

@ -12,6 +12,7 @@ import (
"reflect"
"gitee.com/johng/gf/g/util/gutil"
"gitee.com/johng/gf/g/container/gmap"
"strconv"
)
const (
@ -112,11 +113,11 @@ func (s *Server)SetConfig(c ServerConfig) error {
}
// 设置http server参数 - Addr
func (s *Server)SetAddr(addr string) error {
func (s *Server)SetPort(port int) error {
if s.status == 1 {
return errors.New("server config cannot be changed while running")
}
s.config.Addr = addr
s.config.Addr = ":" + strconv.Itoa(port)
return nil
}

View File

@ -2,14 +2,28 @@
"viewpath" : "/home/john/Workspace/Go/GOPATH/src/gitee.com/johng/gf/geg/frame/mvc/view",
"database" : {
"default" : [
"root@127.0.0.1:3306,123456,test,mysql",
"root@127.0.0.1:3306,123456,test,mysql",
"root@127.0.0.1:3306,123456,test,mysql"
],
"user-center" : [
"root@127.0.0.1:3306,123456,ucenter,mysql",
"root@127.0.0.1:3306,123456,ucenter,mysql",
"root@127.0.0.1:3306,123456,ucenter,mysql"
{
"host" : "127.0.0.1",
"port" : "3306",
"user" : "root",
"pass" : "127456",
"name" : "test",
"type" : "mysql",
"role" : "master",
"charset" : "utf8",
"priority" : "1"
},
{
"host" : "127.0.0.1",
"port" : "3306",
"user" : "root",
"pass" : "127456",
"name" : "test",
"type" : "mysql",
"role" : "master",
"charset" : "utf8",
"priority" : "1"
}
]
}
}

View File

@ -6,6 +6,6 @@ import (
)
func main() {
ghttp.GetServer("johng").SetAddr(":8199")
ghttp.GetServer("johng").SetPort(8199)
ghttp.GetServer("johng").Run()
}