Skip to content

Commit

Permalink
Merge pull request #24 from Dot-Liu/develop
Browse files Browse the repository at this point in the history
修改mod
  • Loading branch information
Eolink authored Oct 14, 2021
2 parents bb9de63 + b4d06b4 commit c5d0093
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 670 deletions.
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/debug/
28 changes: 16 additions & 12 deletions app/goku/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

"github.com/eolinker/eosc"

"github.com/eolinker/eosc/env"
admin_open_api "github.com/eolinker/eosc/modules/admin-open-api"
"github.com/eolinker/eosc/process-master/admin"

Expand All @@ -32,20 +31,25 @@ func init() {
}

func main() {

//defer func() {
// if err := recover(); err != nil {
// log.Error("main recover error: ", err)
// }
// log.Close()
//}()
if process.Run() {
log.Close()
return
}
if env.IsDebug() {
if process.RunDebug(eosc.ProcessMaster) {
log.Info("debug done")
} else {
log.Warn("debug not exist")
}
log.Close()
//log.Close()
return
}
//if env.IsDebug() {
// if process.RunDebug(eosc.ProcessMaster) {
// log.Info("debug done")
// } else {
// log.Warn("debug not exist")
// }
// //log.Close()
// return
//}
app := eoscli.NewApp()
app.AppendCommand(
eoscli.Start(eoscli.StartFunc),
Expand Down
8 changes: 4 additions & 4 deletions app/goku/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import (
"os"

"github.com/eolinker/eosc"
"github.com/eolinker/eosc/utils"

"github.com/eolinker/goku/professions"

process_master "github.com/eolinker/eosc/process-master"
"github.com/eolinker/eosc/utils"

"github.com/eolinker/eosc/log"
"github.com/eolinker/eosc/pidfile"
process_master "github.com/eolinker/eosc/process-master"
)

func ProcessMaster() {
utils.InitLogTransport(eosc.ProcessMaster)

p, err := NewMasterHandler()
if err != nil {
log.Errorf("fail to read procession.yml: %v", err)
return
}
utils.InitLogTransport(eosc.ProcessMaster)
file, err := pidfile.New()
if err != nil {
log.Errorf("the process-master is running:%v by:%d", err, os.Getpid())
Expand Down
2 changes: 2 additions & 0 deletions drivers/router/http-router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package http_router

import (
"github.com/eolinker/eosc"
"github.com/eolinker/eosc/log"
router_http "github.com/eolinker/goku/router/router-http"
"github.com/eolinker/goku/service"
)
Expand Down Expand Up @@ -58,6 +59,7 @@ func (r *Router) Id() string {

//Start 启动路由worker,将路由实例加入到路由树中
func (r *Router) Start() error {
log.Debug("router:start")
return router_http.Add(r.port, r.id, r.conf)
}

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ module github.com/eolinker/goku
go 1.15

require (
github.com/eolinker/eosc v0.1.0
github.com/eolinker/eosc v0.1.1
github.com/eolinker/goku-standard-plugin v0.1.5
github.com/ghodss/yaml v1.0.0
github.com/go-basic/uuid v1.0.0
github.com/hashicorp/consul/api v1.9.1
github.com/pkg/sftp v1.13.2
github.com/robertkrimen/otto v0.0.0-20210614181706-373ff5438452
github.com/satori/go.uuid v1.2.0
github.com/urfave/cli v1.22.5 // indirect
github.com/urfave/cli/v2 v2.3.0 // indirect
github.com/valyala/fasthttp v1.30.0
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
Expand Down
613 changes: 0 additions & 613 deletions go.sum

This file was deleted.

32 changes: 8 additions & 24 deletions router/router-http/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,6 @@ func (m *Manager) Add(port int, id string, config *Config) error {
m.tf.Get(port).SetHttp(router.Handler())
}

//
//if isCreate {
// s, has := m.servers[port]
// if !has {
//
// l, err := m.traffic.ListenTcp("", port)
//
// if err != nil {
// return err
// }
// if config.Protocol == "https" {
// s.certs = newCerts(config.Cert)
// s.tlsConfig = &tls.Config{GetCertificate: s.GetCertificate}
// l = tls.NewListener(l, s.tlsConfig)
// }
// go s.srv.Serve(l)
//
// m.servers[port] = s
//
// }
//}
return nil
}

Expand All @@ -113,9 +92,14 @@ func (m *Manager) Del(port int, id string) error {
defer m.locker.Unlock()
if r, has := m.routers.Del(port, id); has {
//若目标端口的http服务器已无路由配置,则关闭服务器及listener
if r.Count() == 0 {
m.tf.ShutDown(port)
}
count := r.Count()

log.Debug("after delete router,count of port:", port, " count:", count)
//if count == 0 {
// m.tf.ShutDown(port)
//} else if env.IsDebug() {
//
//}
}

return nil
Expand Down
40 changes: 25 additions & 15 deletions router/router-http/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ func NewRouter() *Router {

//Count 返回路由树中配置实例的数量
func (r *Router) Count() int {

return r.data.Count()
}

//Handler 路由树的handler方法
func (r *Router) Handler() fasthttp.RequestHandler {
return func(requestCtx *fasthttp.RequestCtx) {
match := r.match
if match == nil {
requestCtx.NotFound()
return
}
log.Debug("router handler", requestCtx.Request.String())
ctx := http_context.NewContext(requestCtx)
h, e, has := r.match.Match(ctx.Request())
h, e, has := match.Match(ctx.Request())
if !has {
http_context.NotFound(ctx)
requestCtx.NotFound()
return
}
h.Handle(ctx, NewEndPoint(e))
Expand All @@ -64,17 +70,12 @@ func (r *Router) SetRouter(id string, config *Config) error {
data := r.data.Clone()
data.Set(id, config)
//重新生成路由树
list := data.List()
cs := make([]*Config, 0, len(list))
for _, i := range list {
cs = append(cs, i.(*Config))
}
matcher, err := parse(cs)
m, err := parseData(data)
if err != nil {
return err
}

r.match = matcher
r.match = m
r.data = data
return nil
}
Expand All @@ -87,20 +88,29 @@ func (r *Router) Del(id string) int {
data := r.data.Clone()
data.Del(id)
if data.Count() == 0 {
r.data = data
r.match = nil
} else {
//重新生成路由树
list := data.List()
cs := make([]*Config, 0, len(list))
for _, i := range list {
cs = append(cs, i.(*Config))
}
m, err := parse(cs)
m, err := parseData(data)
if err != nil {
// 路由树生成失败, 则放弃
return r.data.Count()
}
// 路由树生成成功,则替换
r.data = data
r.match = m
}

return r.data.Count()
}

func parseData(data eosc.IUntyped) (IMatcher, error) {
list := data.List()
cs := make([]*Config, 0, len(list))
for _, i := range list {
cs = append(cs, i.(*Config))
}
return parse(cs)

}
1 change: 1 addition & 0 deletions router/router-http/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (rs *Routers) Set(port int, id string, conf *Config) (IRouter, bool, error)
rs.data.Set(name, router)
return router, true, nil
}
// todo 这里需要校验端口已使用的的http协议是否与之前配置冲突,并返回新的合并后的证书列表

router := r.(IRouter)
err := router.SetRouter(id, conf)
Expand Down

0 comments on commit c5d0093

Please sign in to comment.