Skip to content

Commit

Permalink
1.更新readme,2.新增kafka连接库,3.logger导出器加入kafka支持,4.中间件新增客户端语言识别,5.其他代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
keepchen committed Dec 26, 2023
1 parent fed5229 commit cf6e7f1
Show file tree
Hide file tree
Showing 21 changed files with 619 additions and 167 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ var (
c.String(http.StatusOK, "%s", "hello, world!")
})
}
fn = func() {
fmt.Println("call user function to do something...")
before = func() {
fmt.Println("call user function [before] to do something...")
}
after = func() {
fmt.Println("call user function [after] to do something...")
}
)

sail.WakeupHttp("go-sail", conf, apiOption).Launch(registerRoutes, fn)
sail.WakeupHttp("go-sail", conf, apiOption).Launch(registerRoutes, before, after)
```
当你看到终端如下图所示内容就表示服务启动成功了:
<img src="./launch.png" alt="launch.png" title="launch.png" width="600" />
Expand Down Expand Up @@ -130,9 +133,9 @@ func (v UserInfo) GetData() interface{} {

//handler
func GetUserInfo(c *gin.Context) {
var resp UserInfo
resp.Data.Nickname = "go-sail"
resp.Data.Age = 18
var resp UserInfo
resp.Data.Nickname = "go-sail"
resp.Data.Age = 18

sail.Response(c).Builder(constants.ErrNone, resp).Send()
}
Expand All @@ -142,7 +145,7 @@ func GetUserInfo(c *gin.Context) {
[README.md](plugins/README.md)

## 使用案例
<img src="static/usecases/pikaster-metaland.png" alt="Pikaster" width="600" />
<img src="static/usecases/wingoal-metaland.png" alt="WinGoal" width="450" />
<img src="static/usecases/miniprogram-hpp.png" alt="生活好评助手-小程序" width="350" />
<img src="static/usecases/pikaster-metaland.png" alt="Pikaster" width="300" />
<img src="static/usecases/wingoal-metaland.png" alt="WinGoal" width="300" />
<img src="static/usecases/miniprogram-hpp.png" alt="生活好评助手-小程序" width="100" />

21 changes: 12 additions & 9 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ var (
c.String(http.StatusOK, "%s", "hello, world!")
})
}
fn = func() {
fmt.Println("call user function to do something...")
before = func() {
fmt.Println("call user function [before] to do something...")
}
after = func() {
fmt.Println("call user function [after] to do something...")
}
)

sail.WakeupHttp("go-sail", conf, apiOption).Launch(registerRoutes, fn)
sail.WakeupHttp("go-sail", conf, apiOption).Launch(registerRoutes, before, after)
```
Console screenshot after launched like this:
<img src="./launch.png" alt="launch.png" title="launch.png" width="600" />
Expand Down Expand Up @@ -130,9 +133,9 @@ func (v UserInfo) GetData() interface{} {

//handler
func GetUserInfo(c *gin.Context) {
var resp UserInfo
resp.Data.Nickname = "go-sail"
resp.Data.Age = 18
var resp UserInfo
resp.Data.Nickname = "go-sail"
resp.Data.Age = 18

sail.Response(c).Builder(constants.ErrNone, resp).Send()
}
Expand All @@ -142,6 +145,6 @@ func GetUserInfo(c *gin.Context) {
[README.md](plugins/README.md)

## Use cases
<img src="static/usecases/pikaster-metaland.png" alt="Pikaster" width="600" />
<img src="static/usecases/wingoal-metaland.png" alt="WinGoal" width="450" />
<img src="static/usecases/miniprogram-hpp.png" alt="生活好评助手-小程序" width="350" />
<img src="static/usecases/pikaster-metaland.png" alt="Pikaster" width="300" />
<img src="static/usecases/wingoal-metaland.png" alt="WinGoal" width="300" />
<img src="static/usecases/miniprogram-hpp.png" alt="生活好评助手-小程序" width="150" />
6 changes: 6 additions & 0 deletions examples/logs/running.log
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,9 @@
{"level":"info","time":"2023-10-31T14:54:14.407+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-10-31T14:54:14.408+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-10-31T14:54:14.408+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-26T13:38:02.197+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-26T13:38:02.198+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-26T13:38:02.198+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-26T14:08:00.903+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-26T14:08:00.904+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-26T14:08:00.904+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
2 changes: 1 addition & 1 deletion examples/pkg/app/user/http/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func RegisterRoutes(r *gin.Engine) {
"Access-Control-Allow-Headers": "Authorization, Content-Type, Content-Length, Some-Other-Headers",
}
//全局打印请求载荷、放行跨域请求、写入Prometheus exporter
r.Use(mdlw.Before(), mdlw.PrintRequestPayload(), mdlw.WithCors(allowHeaders), mdlw.PrometheusExporter())
r.Use(mdlw.RequestEntry(), mdlw.PrintRequestPayload(), mdlw.WithCors(allowHeaders), mdlw.PrometheusExporter())
apiGroup := r.Group("/api/v1")
{
apiGroup.GET("/say-hello", handler.SayHello)
Expand Down
9 changes: 6 additions & 3 deletions examples/pkg/app/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ func StartServer(wg *sync.WaitGroup) {
ErrNoneCodeMsg: "SUCCEED",
ForceHttpCode200: true,
}
fn = func() {
fmt.Println("call user function to do something...")
before = func() {
fmt.Println("call user function [before] to do something...")
}
after = func() {
fmt.Println("call user function [after] to do something...")
}
)

sail.WakeupHttp("go-sail", conf, apiOption).Launch(routes.RegisterRoutes, fn)
sail.WakeupHttp("go-sail", conf, apiOption).Launch(routes.RegisterRoutes, before, after)
}

// RegisterServicesToNacos 将服务注册到注册中心
Expand Down
14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ require (
github.com/jinzhu/configor v1.2.1
github.com/nacos-group/nacos-sdk-go/v2 v2.1.2
github.com/nats-io/nats.go v1.26.0
github.com/pelletier/go-toml/v2 v2.0.8
github.com/prometheus/client_golang v1.14.0
github.com/segmentio/kafka-go v0.4.47
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.4
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a
github.com/swaggo/gin-swagger v1.5.3
github.com/swaggo/swag v1.8.8
go.uber.org/zap v1.24.0
golang.org/x/net v0.10.0
golang.org/x/net v0.17.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.4.0
gorm.io/driver/clickhouse v0.5.0
Expand Down Expand Up @@ -92,7 +94,6 @@ require (
github.com/nats-io/nkeys v0.4.4 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/paulmach/orb v0.7.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -104,15 +105,18 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
Expand Down
Loading

0 comments on commit cf6e7f1

Please sign in to comment.