Skip to content

Commit

Permalink
Merge pull request #23 from Dot-Liu/develop
Browse files Browse the repository at this point in the history
v0.2.0-beta publish
  • Loading branch information
Eolink authored Sep 30, 2021
2 parents 14a8370 + 508e620 commit 4de720e
Show file tree
Hide file tree
Showing 18 changed files with 694 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# vendor/
/.idea/
/vendor/
/go.sum
5 changes: 5 additions & 0 deletions app/goku/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/eosc-*/
goku*
*.log
/export/
/runtime_config/
12 changes: 11 additions & 1 deletion app/goku/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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 @@ -24,7 +25,7 @@ import (
)

func init() {
admin.Register("/api", admin_open_api.CreateHandler())
admin.Register("/api/", admin_open_api.CreateHandler())
process.Register(eosc.ProcessWorker, ProcessWorker)
process.Register(eosc.ProcessMaster, ProcessMaster)
process.Register(eosc.ProcessHelper, ProcessHelper)
Expand All @@ -36,6 +37,15 @@ func main() {
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
23 changes: 18 additions & 5 deletions app/goku/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@ package main
import (
"os"

"github.com/eolinker/eosc"

"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"
)

func ProcessMaster() {
process_master.InitLogTransport()
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())
return
}
master := process_master.NewMasterHandle(file)
if err := master.Start(NewMasterHandler()); err != nil {

if err := master.Start(p); err != nil {
master.Close()
log.Errorf("process-master[%d] start faild:%v", os.Getpid(), err)
return
Expand All @@ -28,8 +37,12 @@ func ProcessMaster() {
master.Wait()
}

func NewMasterHandler() *process_master.MasterHandler {
return &process_master.MasterHandler{
Professions: professions.NewProfessions("profession.yml"),
func NewMasterHandler() (*process_master.MasterHandler, error) {
p, err := professions.NewProfessions("profession.yml")
if err != nil {
return nil, err
}
return &process_master.MasterHandler{
Professions: p,
}, nil
}
14 changes: 14 additions & 0 deletions app/goku/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"github.com/eolinker/goku/drivers/discovery/eureka"
"github.com/eolinker/goku/drivers/discovery/nacos"
"github.com/eolinker/goku/drivers/discovery/static"
"github.com/eolinker/goku/drivers/log/filelog"
"github.com/eolinker/goku/drivers/log/httplog"
"github.com/eolinker/goku/drivers/log/stdlog"
"github.com/eolinker/goku/drivers/log/syslog"
http_router "github.com/eolinker/goku/drivers/router/http-router"
service_http "github.com/eolinker/goku/drivers/service/service-http"
upstream_http "github.com/eolinker/goku/drivers/upstream/upstream-http"
)
Expand All @@ -20,6 +25,9 @@ func ProcessWorker() {
}

func register() {
// router
http_router.Register()

// service
service_http.Register()

Expand All @@ -37,4 +45,10 @@ func register() {
apikey.Register()
aksk.Register()
jwt.Register()

// log
filelog.Register()
httplog.Register()
syslog.Register()
stdlog.Register()
}
20 changes: 0 additions & 20 deletions build/resources/data.yaml

This file was deleted.

1 change: 1 addition & 0 deletions build/resources/profession.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
desc: 注册中心
dependencies: null
append_label:
# - health_on
drivers:
-
id: eolinker:goku:discovery_static
Expand Down
2 changes: 2 additions & 0 deletions drivers/discovery/nacos/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func (d *driver) ConfigType() reflect.Type {
func (d *driver) Create(id, name string, v interface{}, workers map[eosc.RequireId]interface{}) (eosc.IWorker, error) {
cfg, ok := v.(*Config)
if !ok {
val := reflect.ValueOf(v)
fmt.Println("reflect", val.Kind(), val.Interface())
return nil, fmt.Errorf("need %s,now %s", eosc.TypeNameOf((*Config)(nil)), eosc.TypeNameOf(v))
}
return &nacos{
Expand Down
2 changes: 1 addition & 1 deletion drivers/log/httplog/httplog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestHTTPLog(t *testing.T) {

// 测试Reset
newDriverConfig := &DriverConfig{
Name: "Tesethttplog",
Name: "Testhttplog",
Driver: "httplog",
Method: "GET",
URL: "http://127.0.0.1:8081/test",
Expand Down
10 changes: 1 addition & 9 deletions drivers/router/http-router/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@ import (

//HTTPRouterDriver 实现github.com/eolinker/eosc.eosc.IProfessionDriver接口
type HTTPRouterDriver struct {
info eosc.DriverInfo
configType reflect.Type
}

//NewHTTPRouter 创建一个http路由驱动
func NewHTTPRouter(profession, name, label, desc string, params map[string]string) *HTTPRouterDriver {
return &HTTPRouterDriver{
configType: reflect.TypeOf(new(DriverConfig)),
info: eosc.DriverInfo{
Name: name,
Label: label,
Desc: desc,
Profession: profession,
Params: params,
},
}
}

Expand All @@ -51,7 +43,7 @@ func (h *HTTPRouterDriver) check(v interface{}, workers map[eosc.RequireId]inter
}
target, ok := ser.(service.IService)
if !ok {
return nil, nil, fmt.Errorf("target %w", eosc.ErrorNotGetSillForRequire)
return nil, nil, fmt.Errorf("target name: %s type of %s,target %w", conf.Target, eosc.TypeNameOf(ser), eosc.ErrorNotGetSillForRequire)
}
return conf, target, nil

Expand Down
5 changes: 5 additions & 0 deletions drivers/router/http-router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type Router struct {
driver *HTTPRouterDriver
}

func (r *Router) Ports() []int {

return []int{r.port}
}

//Reset 重置http路由配置
func (r *Router) Reset(conf interface{}, workers map[eosc.RequireId]interface{}) error {
cf, target, err := r.driver.check(conf, workers)
Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/eolinker/goku
go 1.15

require (
github.com/eolinker/eosc v0.0.9
github.com/eolinker/eosc v0.1.0
github.com/eolinker/goku-standard-plugin v0.1.5
github.com/ghodss/yaml v1.0.0
github.com/go-basic/uuid v1.0.0
Expand All @@ -13,9 +13,11 @@ require (
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.28.0
github.com/valyala/fasthttp v1.30.0
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/mod v0.5.1 // indirect
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
golang.org/x/tools v0.1.7 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
)

replace github.com/eolinker/eosc => ../eosc
Loading

0 comments on commit 4de720e

Please sign in to comment.