提交 cd8e4a1b 编写于 作者: Y Your Name

3.1.3版本提交

上级 eb06f999
package main
import (
"github.com/eolinker/goku-api-gateway/common/database"
"strconv"
"github.com/pkg/errors"
"github.com/eolinker/goku-api-gateway/common/conf"
"github.com/eolinker/goku-api-gateway/server/entity"
)
func getDefaultDatabase() (*entity.ClusterDB, error) {
dbType := conf.MastValue("db_type", "sqlite3")
switch dbType {
case database.MysqlDriver:
{
dbPort, err := strconv.Atoi(conf.MastValue("db_port", "3306"))
if err != nil {
return nil, err
}
return &entity.ClusterDB{
Driver: dbType,
Host: conf.Value("db_host"),
Port: dbPort,
UserName: conf.Value("db_user"),
Password: conf.Value("db_password"),
Database: conf.Value("db_name"),
}, nil
}
case database.Sqlite3Driver:
{
return &entity.ClusterDB{
Driver: dbType,
Path: conf.MastValue("db_path", "./work/goku.db"),
}, nil
}
default:
{
return nil, errors.New("unsupported database type")
}
}
}
package main
import (
"fmt"
"github.com/eolinker/goku-api-gateway/common/database"
"github.com/eolinker/goku-api-gateway/common/pdao"
console_sqlite3 "github.com/eolinker/goku-api-gateway/server/dao/console-sqlite3"
"github.com/eolinker/goku-api-gateway/server/entity"
)
//ClusterDatabaseConfig 集群数据库配置
type ClusterDatabaseConfig entity.ClusterDB
//GetDriver 获取驱动类型
func (c *ClusterDatabaseConfig) GetDriver() string {
return c.Driver
}
//GetSource 获取连接字符串
func (c *ClusterDatabaseConfig) GetSource() string {
switch c.Driver {
case database.MysqlDriver:
{
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8", c.UserName, c.Password, c.Host, c.Port, c.Database)
}
case database.Sqlite3Driver:
{
return c.Path
}
default:
{
return ""
}
}
}
//InitDatabase 初始化数据库
func InitDatabase() {
console_sqlite3.DoRegister()
def, err := getDefaultDatabase()
if err != nil {
panic(err)
}
c := ClusterDatabaseConfig(*def)
db,e := database.InitConnection(&c)
if e != nil {
panic(e)
}
err =pdao.Build(c.GetDriver(),db)
if err!=nil{
panic(err)
}
err =pdao.Check()
if err!=nil{
panic(err)
}
}
package main
import (
module "github.com/eolinker/goku-api-gateway/console/module/config-log"
log "github.com/eolinker/goku-api-gateway/goku-log"
)
//InitLog 初始化日志
func InitLog() {
c, _ := module.Get(module.ConsoleLog)
period, _ := log.ParsePeriod(c.Period)
log.SetOutPut(c.Enable, c.Dir, c.File, period, c.Expire)
l, _ := log.ParseLevel(c.Level)
log.SetLevel(l)
}
......@@ -2,13 +2,11 @@ package main
import (
"flag"
"github.com/eolinker/goku-api-gateway/console/module/account"
log "github.com/eolinker/goku-api-gateway/goku-log"
"github.com/eolinker/goku-api-gateway/common/conf"
"github.com/eolinker/goku-api-gateway/common/general"
"github.com/eolinker/goku-api-gateway/console"
"github.com/eolinker/goku-api-gateway/console/module/account"
"github.com/eolinker/goku-api-gateway/utils"
)
......@@ -33,21 +31,20 @@ func main() {
log.Panic(err)
return
}
// 初始化db
console.InitDatabase()
console.InitLog()
InitDatabase()
InitLog()
//console.InitClusters()
// 其他需要初始化的模块
_ = general.General()
// 检测是否安装
s, err := account.CheckSuperAdminCount()
if err != nil {
err = console.InitTable()
if err != nil {
log.Panic(err)
return
}
}
if s == 0 {
if userName == "" {
......@@ -62,13 +59,13 @@ func main() {
// 用户注册
password := utils.Md5(utils.Md5(userPassword))
f := console.Register(userName, password)
f := account.Register(userName, password)
if !f {
log.Fatal("[ERROR] Fail to create administrator. Please try again or contact technical support of eoLinker GOKU API Gateway.")
return
}
}
console.Router()
console.Server()
Server()
//console.Router()
//console.Server()
}
package main
import (
graphite "github.com/eolinker/goku-api-gateway/module/graphite/config"
prometheus "github.com/eolinker/goku-api-gateway/module/prometheus/config"
)
func moduleRegister() {
prometheus.Register()
graphite.Register()
}
package main
import (
"net/http"
account_default "github.com/eolinker/goku-api-gateway/console/account"
"github.com/eolinker/goku-api-gateway/console/controller/account"
"github.com/eolinker/goku-api-gateway/console/controller/api"
"github.com/eolinker/goku-api-gateway/console/controller/auth"
"github.com/eolinker/goku-api-gateway/console/controller/balance"
"github.com/eolinker/goku-api-gateway/console/controller/cluster"
config_log "github.com/eolinker/goku-api-gateway/console/controller/config-log"
"github.com/eolinker/goku-api-gateway/console/controller/discovery"
"github.com/eolinker/goku-api-gateway/console/controller/gateway"
"github.com/eolinker/goku-api-gateway/console/controller/monitor"
"github.com/eolinker/goku-api-gateway/console/controller/node"
"github.com/eolinker/goku-api-gateway/console/controller/plugin"
"github.com/eolinker/goku-api-gateway/console/controller/project"
"github.com/eolinker/goku-api-gateway/console/controller/strategy"
goku_handler "github.com/eolinker/goku-api-gateway/goku-handler"
)
var (
accountFactory = goku_handler.NewAccountHandlerFactory(account_default.NewDefaultAccount())
)
func router() http.Handler {
s := goku_handler.NewGokuServer(accountFactory)
// 账号管理模块
s.Add("/guest", account.NewAccountController())
s.Add("/user", account.NewUserController())
// 接口管理模块
s.Add("/apis", api.NewAPIHandlers())
s.Add("/apis/group", api.NewGroupHandlers())
s.Add("/import/ams", api.NewImportHandlers())
s.Add("/plugin/api", api.NewPluginHandlers())
// 鉴权模块
s.Add("/auth", auth.NewHandlers())
// 负载模块
s.Add("/balance", balance.NewHandlers())
// 集群模块
s.Add("/cluster", cluster.NewHandlers())
s.Add("/version/config", cluster.NewVersionHandlers())
// 日志配置模块
s.Add("/config/log", config_log.NewHandlers())
// 服务发现模块
s.Add("/balance/service", discovery.NewHandlers())
// 网关模块
s.Add("/monitor/gateway", gateway.NewHandlers())
// 监控模块
s.Add("/monitor/module/config", monitor.NewHandlers())
// 节点模块
s.Add("/node", node.NewNodeHandlers())
s.Add("/node/group", node.NewGroupHandlers())
// 插件模块
s.Add("/plugin", plugin.NewHandlers())
// 项目模块
s.Add("/project", project.NewHandlers())
// 策略模块
s.Add("/strategy", strategy.NewStrategyHandlers())
s.Add("/strategy/group", strategy.NewGroupHandlers())
s.Add("/strategy/api", strategy.NewAPIStrategyHandlers())
s.Add("/plugin/strategy", strategy.NewPluginHandlers())
// 前端接入
s.Add("/", new(staticHandlers))
return s
}
type staticHandlers struct {
}
func (s *staticHandlers) Handlers(factory *goku_handler.AccountHandlerFactory) map[string]http.Handler {
return map[string]http.Handler{
"/": http.StripPrefix("/", http.FileServer(http.Dir("./static"))),
}
}
package main
import (
"log"
"net/http"
"github.com/eolinker/goku-api-gateway/admin/console"
"github.com/eolinker/goku-api-gateway/common/conf"
)
//Server 控制台服务
func Server() {
moduleRegister()
bind, has := conf.Get("admin_bind")
if !has {
log.Panic("[ERROR] Illegal admin_bind!")
return
}
err := console.Start(bind)
if err != nil {
log.Fatal(err)
return
}
ec := make(chan error, 1)
port, has := conf.Get("listen_port")
if has {
go func() {
log.Print("Listen: ", port)
log.Print("Start Successfully!")
err := http.ListenAndServe(":7000", router())
ec <- err
}()
} else {
log.Panic("[ERROR] Illegal listen port!")
}
for {
select {
case e, ok := <-ec:
if !ok {
break
}
log.Fatal(e)
}
}
}
package main
import (
"github.com/eolinker/goku-api-gateway/goku-service/driver/consul"
"github.com/eolinker/goku-api-gateway/goku-service/driver/eureka"
"github.com/eolinker/goku-api-gateway/goku-service/driver/static"
"github.com/eolinker/goku-api-gateway/goku-service/driver/consul"
"github.com/eolinker/goku-api-gateway/goku-service/driver/eureka"
"github.com/eolinker/goku-api-gateway/goku-service/driver/static"
)
func init() {
consul.Register()
eureka.Register()
static.Register()
}
\ No newline at end of file
}
......@@ -9,4 +9,4 @@ func init() {
prometheus.Register()
graphite.Register()
}
\ No newline at end of file
}
......@@ -2,9 +2,9 @@ package main
import (
"flag"
"github.com/eolinker/goku-api-gateway/admin/node"
"github.com/eolinker/goku-api-gateway/config"
log "github.com/eolinker/goku-api-gateway/goku-log"
console2 "github.com/eolinker/goku-api-gateway/node/console"
"github.com/eolinker/goku-api-gateway/node/server"
"runtime"
)
......@@ -20,7 +20,8 @@ func main() {
if admin != "" && instance != ""{
console := console2.NewConsole(instance, admin)
console := node.NewConsole(admin,instance)
ser := server.NewServer()
log.Fatal(ser.ServerWidthConsole(console))
return
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册