Skip to content

Commit

Permalink
Debug Go-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Jul 10, 2022
1 parent dcc27e7 commit 7775feb
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ jobs:
name: Wait for Souin is really loaded inside Go-zero as middleware
uses: jakejarvis/wait-action@master
with:
time: 70s
time: 50s
-
name: Set Go-zero logs configuration result as environment variable
run: cd plugins/go-zero && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow_plugins_generator.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

plugins=("beego" "chi" "dotweb" "echo" "fiber" "gin" "go-zero" "goyave" "kratos" "skipper" "souin" "traefik" "tyk" "webgo")
durations=("35" "30" "30" "30" "45" "30" "70" "35" "50" "60" "40" "30" "30" "30")
durations=("35" "30" "30" "30" "45" "30" "50" "35" "50" "60" "40" "30" "30" "30")
versions=("16" "16" "16" "16" "16" "16" "16" "16" "18" "18" "16" "16" "16" "16")

IFS= read -r -d '' tpl <<EOF
Expand Down
5 changes: 4 additions & 1 deletion plugins/go-zero/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
etc/
internal/
internal/config/
internal/logic/
internal/svc/
internal/types/
2 changes: 1 addition & 1 deletion plugins/go-zero/examples/httpcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ func main() {
var c config.Config
conf.MustLoad(*configFile, &c)

ctx := svc.NewServiceContext(c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()

ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)

fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
Expand Down
28 changes: 28 additions & 0 deletions plugins/go-zero/examples/internal/handler/mainhandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package handler

import (
"net/http"

"github.com/darkweak/souin/plugins/go-zero/examples/internal/logic"
"github.com/darkweak/souin/plugins/go-zero/examples/internal/svc"
"github.com/darkweak/souin/plugins/go-zero/examples/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)

func mainHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CacheReq
if err := httpx.Parse(r, &req); err != nil {
httpx.Error(w, err)
return
}

l := logic.NewMainLogic(r.Context(), svcCtx)
resp, err := l.Main(&req)
if err != nil {
httpx.Error(w, err)
} else {
httpx.OkJson(w, resp)
}
}
}
27 changes: 27 additions & 0 deletions plugins/go-zero/examples/internal/handler/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions plugins/go-zero/examples/internal/handler/souinapihandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package handler

import (
"net/http"

"github.com/darkweak/souin/plugins/go-zero/examples/internal/logic"
"github.com/darkweak/souin/plugins/go-zero/examples/internal/svc"
"github.com/darkweak/souin/plugins/go-zero/examples/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)

func souin_apiHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CacheReq
if err := httpx.Parse(r, &req); err != nil {
httpx.Error(w, err)
return
}

l := logic.NewSouin_apiLogic(r.Context(), svcCtx)
resp, err := l.Souin_api(&req)
if err != nil {
httpx.Error(w, err)
} else {
httpx.OkJson(w, resp)
}
}
}
2 changes: 0 additions & 2 deletions plugins/go-zero/examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"flag"

cache "github.com/darkweak/souin/plugins/go-zero"

"github.com/darkweak/souin/plugins/go-zero/examples/internal/config"
"github.com/darkweak/souin/plugins/go-zero/examples/internal/handler"
"github.com/darkweak/souin/plugins/go-zero/examples/internal/svc"
Expand All @@ -27,7 +26,6 @@ func main() {

httpcache := cache.NewHTTPCache(cache.DevDefaultConfiguration)
server.Use(httpcache.Handle)

handler.RegisterHandlers(server, ctx)

server.Start()
Expand Down
2 changes: 1 addition & 1 deletion plugins/go-zero/examples/sample.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Name: httpcache
Host: 0.0.0.0
Port: 80
Port: 80
5 changes: 1 addition & 4 deletions plugins/go-zero/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/darkweak/souin v1.6.12
github.com/go-chi/chi/v5 v5.0.7
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/flatbuffers v2.0.6+incompatible // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand All @@ -19,15 +18,13 @@ require (
github.com/klauspost/compress v1.15.7 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/prometheus/common v0.35.0 // indirect
github.com/zeromicro/go-zero v1.3.2
github.com/zeromicro/go-zero v1.3.0
go.opencensus.io v0.23.0 // indirect
golang.org/x/net v0.0.0-20220630215102-69896b714898 // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220702020025-31831981b65f // indirect
golang.org/x/tools v0.1.11 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/genproto v0.0.0-20220630174209-ad1d48641aa7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/darkweak/souin v1.6.12 => ../..
Loading

0 comments on commit 7775feb

Please sign in to comment.