Skip to content

Commit

Permalink
add config
Browse files Browse the repository at this point in the history
  • Loading branch information
bobkentt committed Dec 29, 2016
1 parent c513daa commit cfd7d8a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
26 changes: 25 additions & 1 deletion config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,31 @@ type APIConfig struct {
Addr string `json:"addr"`
}

type DBConfig struct {
Usr string `json:"domain"`
Passwd string `json:"addr"`
MaxIdle uint32 `jons:"max_idle"`
MaxConn uint32 `jons:"max_conn"`
}

type ConfigStruct struct {
API APIConfig `json:"api"`
Dbkeys DBConfig `json:"dbkeys"`
//API APIConfig `json:"api"`
}

var (
Config ConfigStruct
)

func LoadConfig(filename string) error {
r, err := os.Open(filename)
if err != nil {
return err
}
decoder := json.NewDecoder(r)
err = decoder.Decode(&Config)
if err != nil {
return err
}
return nil
}
15 changes: 15 additions & 0 deletions fairy-api/controllers/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package controllers

import (
"fmt"
)

type MenuController struct {
BaseController
}

func (this *MenuController) GetMenuList() {
fmt.Printf("Call GetMenuList\n")
return
}

22 changes: 20 additions & 2 deletions fairy-api/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
package main

import (
_ "fairy/fairy-api/routers"
"fmt"

"github.com/astaxie/beego"

_ "fairy/fairy-api/routers"
"fairy/config"
)

func main() {
beego.Run()
// param parse
var configFile = flag.String("c", "./conf/conf.json", "Config file")
flag.Parse()

// config load
err := conf.LoadConfig(*configFile)
if err != nil {
fmt.Printf("LoadConfig (%s) failed: (%s)\n", *configFile, err)
os.Exit(1)
}

// server run
go func() {
beego.Run()
}()
}

3 changes: 3 additions & 0 deletions fairy-api/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ func init() {
// bless
beego.Router("/api/v1/bless", &controllers.BlessController{}, "get:Get")

// menu
beego.Router("/api/v1/metu/list", &controllers.BlessController{}, "get:GetMetuList")

// usr
beego.Router("/api/v1/usr", &controllers.UsrController{}, "post:Post")
beego.Router("/api/v1/usr/cheer", &controllers.UsrController{}, "post:Cherr")
Expand Down
13 changes: 13 additions & 0 deletions storage/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package storage

import (
"fmt"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
)

func NewInstance() {
// set default database
orm.RegisterDataBase("fairy", "mysql", "root:root@/my_db?charset=utf8", 30)

}

0 comments on commit cfd7d8a

Please sign in to comment.