Skip to content

Commit

Permalink
Merge pull request #23 from Dot-Liu/master
Browse files Browse the repository at this point in the history
完善注释
  • Loading branch information
Eolink authored Sep 28, 2019
2 parents a8e546a + ab0b8b9 commit 63fe5b8
Show file tree
Hide file tree
Showing 228 changed files with 2,518 additions and 2,483 deletions.
3 changes: 2 additions & 1 deletion app/console/config/cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cluster:
- name: "Default"
-
name: "Default"
title: "默认机房"
note: "默认机房"
db:
Expand Down
3 changes: 3 additions & 0 deletions app/console/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
)

var (
// UserPassword 用户密码
UserPassword string
// UserName 用户名
UserName string
// ConfFilePath 配置文件地址
ConfFilePath = "./config/goku.conf"

)
Expand Down
6 changes: 3 additions & 3 deletions app/goku-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/eolinker/goku-api-gateway/common/database"
"github.com/eolinker/goku-api-gateway/common/general"
"github.com/eolinker/goku-api-gateway/common/redis-manager"
redis_manager "github.com/eolinker/goku-api-gateway/common/redis-manager"
goku_node "github.com/eolinker/goku-api-gateway/goku-node"
"github.com/eolinker/goku-api-gateway/server/entity"
)
Expand Down Expand Up @@ -69,11 +69,11 @@ func main() {
return
}
goku_node.InitLog()
log.Debug("goku_node.InitLog")
log.Debug("gokNode.InitLog")
r := redis_manager.Create(&config.Redis)
redis_manager.SetDefault(r)

log.Debug("redis_manager.SetDefault")
log.Debug("redis-manager.SetDefault")
// 其他需要初始化的模块
_ = general.General()

Expand Down
44 changes: 0 additions & 44 deletions build/console/resources/html/redisAlert.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@
</tr>
<tr>
<td style="line-height: 1.75em;">
<h2>GoKu告警节点自动重启失败请及时重启节点</h2>
<h2>GoKu告警$requestURL接口在$alertPeriod分钟内转发失败$alertCount次</h2>
</td>
</tr>
<tr>
<td>
<p style="color:#333;font-size:14px;margin:15px 0 40px 0;">GoKu接口网关于 <b>$alertTime</b>
检测到以下节点重启失败详细日志内容请于 <b>./log/nodeMonitorLog</b> 文件查看
<p style="color:#333;font-size:14px;margin:15px 0 40px 0;">GoKu接口网关于 <b>$alertTime</b> 监控到<b>
$requestURL </b>接口在 <b>$alertPeriod</b> 分钟内转发失败达到 <b>$alertCount</b> 详细告警内容请于
<b>$alertLogPath</b> 文件夹查看</p>
</td>
</tr>
<tr>
<td style="padding:40px 0 5px 0;line-height: 1.75em;border-top:1px solid #e5e5e5;">
<h3>自动重启失败的节点列表</h3>
<h3>接口基本信息</h3>
</td>
</tr>
<tr>
<td style="line-height: 1.75em; padding-bottom: 40px;">
$nodeList
<p>接口名称:$apiName</p>
<p>apiID:$apiID</p>
<p>请求路径:$requestURL</p>
<p>转发路径:$targetServer</p>
<p>映射路径:$proxyURL</p>
</td>
</tr>
</tbody>
Expand Down
8 changes: 7 additions & 1 deletion common/auto-form/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
"unsafe"
)

//Values values
type Values interface {
Get(key string) (string, bool)
}

//ValuesForm valuesForm
type ValuesForm map[string][]string

// Get gets the first value associated with the given key.
Expand All @@ -41,6 +43,7 @@ type (
ContextHandle interface {
SetContext(ctx Values) error
}
//CheckOptHandler 判断是否有opt字段
CheckOptHandler interface {
IsOpt(key string) bool
}
Expand All @@ -50,6 +53,7 @@ type (
}
)

//IsOpt 是否是opt字段
func IsOpt(key string, c interface{}) bool {
val := reflect.ValueOf(c).Elem()
typ := val.Type()
Expand All @@ -67,8 +71,10 @@ func IsOpt(key string, c interface{}) bool {
return false
}

//ErrorNil error nil
var ErrorNil = errors.New("target is nil")
// SetContext 从url.Values中完成配置字段,context中不存在时,使用 default

// SetValues 从url.Values中完成配置字段,context中不存在时,使用 default
// 字段格式 opt:"name,require" default:"default value" min:"min value" max:"max value"
// require 为可选,表示该字段是否为必填
func SetValues(values url.Values, c interface{}) error {
Expand Down
19 changes: 11 additions & 8 deletions common/conf/conf.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// 读取配置信息
package conf

import (
Expand All @@ -13,27 +12,37 @@ var (
lastFile = ""
)

//Get get
func Get(name string) (string, bool) {
v, has := _Configure[name]
return v, has
}

//Set set
func Set(name, value string) {
_Configure[name] = value
}

//Value value
func Value(name string) string {
return _Configure[name]
}

//Reload reload
func Reload() {
ReadConfigure(lastFile)
}

//MastValue mastValue
func MastValue(name string, def string) string {
v, h := _Configure[name]
if h {
return v
}
return def
}

//ReadConfigure 读取配置
func ReadConfigure(filepath string) error {
file, err := os.Open(filepath)
if err != nil {
Expand All @@ -53,14 +62,8 @@ func ReadConfigure(filepath string) error {
return nil
}

// 更新配置文件
//Save 更新配置文件
func Save() (bool, error) {
//file, err := os.OpenFile(lastFile, os.O_CREATE|os.O_WRONLY, 0666)
//if err != nil {
// panic(err)
//}
//defer file.Close()

confStr, err := yaml.Marshal(_Configure)
if err != nil {
return false, err
Expand Down
3 changes: 3 additions & 0 deletions common/database/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package database
import (
"database/sql"
log "github.com/eolinker/goku-api-gateway/goku-log"
// mysql包
_ "github.com/go-sql-driver/mysql"
)

Expand All @@ -14,6 +15,7 @@ var (
defaultDB *sql.DB
)

//InitConnection 初始化连接
func InitConnection(config Config) error {
db, e := getConnection(config)
defaultDB = db
Expand Down Expand Up @@ -45,6 +47,7 @@ func getConnection(config Config) (*sql.DB, error) {

}

//GetConnection 获取连接
func GetConnection() *sql.DB {

return defaultDB
Expand Down
19 changes: 15 additions & 4 deletions common/endless/endless.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ import (
)

const (
//PRE_SIGNAL pre signal
PRE_SIGNAL = iota

//POST_SIGNAL post signal
POST_SIGNAL

//STATE_INIT state init
STATE_INIT
//STATE_RUNNING state running
STATE_RUNNING
//STATE_SHUTTING_DOWN state shutting down
STATE_SHUTTING_DOWN
//STATE_TERMINATE state terminate
STATE_TERMINATE
)

Expand All @@ -36,18 +43,22 @@ var (
socketPtrOffsetMap map[string]uint
runningServersForked bool

DefaultReadTimeOut time.Duration
DefaultWriteTimeOut time.Duration
//DefaultReadTimeOut 默认读超时时间
DefaultReadTimeOut time.Duration
//DefaultWriteTimeOut 默认写超时时间
DefaultWriteTimeOut time.Duration
//DefaultMaxHeaderBytes 默认请求头最大字节数
DefaultMaxHeaderBytes int
DefaultHammerTime time.Duration
//DefaultHammerTime default hammer time
DefaultHammerTime time.Duration

isChild bool
socketOrder string

hookableSignals []os.Signal
)

var isStop bool = true
var isStop = true

func init() {
runningServerReg = sync.RWMutex{}
Expand Down
5 changes: 5 additions & 0 deletions common/general/general.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package general

//InitFunc init func
type InitFunc func() error

var (
_initFunc []InitFunc
_laterFunc []InitFunc
)

//RegeditInit 初始化注册
func RegeditInit(fn InitFunc) {

_initFunc = append(_initFunc, fn)
}

//General general
func General() error {
for _, fn := range _initFunc {
if err := fn(); err != nil {
Expand All @@ -25,6 +29,7 @@ func General() error {
return nil
}

//RegeditLater regedit later
func RegeditLater(fn InitFunc) {
_laterFunc = append(_laterFunc, fn)
}
3 changes: 2 additions & 1 deletion common/redis-manager/factory.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redis_manager
package redismanager

import (
"fmt"
Expand All @@ -11,6 +11,7 @@ const (
_PoolSize = 2000
)

//Create 创建
func Create(config RedisConfig) Redis {

switch config.GetMode() {
Expand Down
2 changes: 1 addition & 1 deletion common/redis-manager/function.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redis_manager
package redismanager

//
//func GetKeys(r Redis, pattern string) ([]string, error) {
Expand Down
5 changes: 4 additions & 1 deletion common/redis-manager/manager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redis_manager
package redismanager

import (
"sync"
Expand All @@ -11,6 +11,7 @@ var (
locker sync.RWMutex
)

//InitRedisOfCluster 初始化集群redis
func InitRedisOfCluster(rs map[string]RedisConfig) {
locker.Lock()
defer locker.Unlock()
Expand All @@ -27,6 +28,8 @@ func get(name string) (Redis, bool) {

return r, h
}

//Get 获取redis
func Get(name string) (Redis, bool) {
r, has := get(name)

Expand Down
2 changes: 1 addition & 1 deletion common/redis-manager/proxy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redis_manager
package redismanager

import (
"github.com/go-redis/redis"
Expand Down
10 changes: 7 additions & 3 deletions common/redis-manager/redis.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package redis_manager
package redismanager

import "github.com/go-redis/redis"

const (
RedisModeCluster = "cluster"
RedisModeStand = "stand"
//RedisModeCluster cluster模式
RedisModeCluster = "cluster"
//RedisModeStand stand模式
RedisModeStand = "stand"
)

//Redis redis
type Redis interface {
redis.Cmdable
GetConfig() RedisConfig
//Foreach(fn func(client *localRedis.Client) error) error
Nodes() []string
}

//RedisConfig redis config
type RedisConfig interface {
GetMode() string
GetAddrs() []string
Expand Down
Loading

0 comments on commit 63fe5b8

Please sign in to comment.