Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/debug/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"path/filepath"
"sort"

"github.com/gofiber/fiber/v2"
fiber "github.com/gofiber/fiber/v3"
g "github.com/maragudk/gomponents"
c "github.com/maragudk/gomponents/components"
h "github.com/maragudk/gomponents/html"
Expand All @@ -16,7 +16,7 @@ func init() {
}

func initDebug() {
debug.Get("/", func(ctx *fiber.Ctx) error {
debug.Get("/", func(ctx fiber.Ctx) error {
pathMap := make(map[string]interface{})
stack := debug.App().Stack()
for m := range stack {
Expand Down
4 changes: 2 additions & 2 deletions core/debug/debug/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"sync"

"github.com/gofiber/fiber/v2"
fiber "github.com/gofiber/fiber/v3"
"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/config"
"github.com/pubgo/funk/errors"
Expand All @@ -27,7 +27,7 @@ var (

func init() {
log.Info().Str("password", running.InstanceID).Msg("debug password")
debug.App().Use(func(c *fiber.Ctx) (gErr error) {
debug.App().Use(func(c fiber.Ctx) (gErr error) {
defer recovery.Recovery(func(err error) {
err = errors.WrapTag(err,
errors.T("headers", c.GetReqHeaders()),
Expand Down
4 changes: 2 additions & 2 deletions core/debug/healthy/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"time"

jjson "github.com/goccy/go-json"
"github.com/gofiber/fiber/v2"
fiber "github.com/gofiber/fiber/v3"
"github.com/pubgo/funk/try"
"github.com/pubgo/lava/core/debug"
"github.com/pubgo/lava/core/healthy"
)

func init() {
debug.Get("/health", func(ctx *fiber.Ctx) error {
debug.Get("/health", func(ctx fiber.Ctx) error {
dt := make(map[string]*health)
for _, name := range healthy.List() {
h := &health{}
Expand Down
74 changes: 54 additions & 20 deletions core/debug/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"net/http"

_ "github.com/fasthttp/router"
"github.com/gofiber/adaptor/v2"
"github.com/gofiber/fiber/v2"
fiber "github.com/gofiber/fiber/v3"
adaptor "github.com/gofiber/fiber/v3/middleware/adaptor"
)

type Config struct {
Expand All @@ -16,26 +16,60 @@ type Config struct {

var app = fiber.New()

func Handler(ctx *fiber.Ctx) error {
func Handler(ctx fiber.Ctx) error {
app.Handler()(ctx.Context())
return nil
}

func App() *fiber.App { return app }
func WrapFunc(h http.HandlerFunc) fiber.Handler { return adaptor.HTTPHandlerFunc(h) }
func Wrap(h http.Handler) fiber.Handler { return adaptor.HTTPHandler(h) }
func Get(path string, handlers ...fiber.Handler) { app.Get(path, handlers...) }
func Head(path string, handlers ...fiber.Handler) { app.Head(path, handlers...) }
func Post(path string, handlers ...fiber.Handler) { app.Post(path, handlers...) }
func Put(path string, handlers ...fiber.Handler) { app.Put(path, handlers...) }
func Delete(path string, handlers ...fiber.Handler) { app.Delete(path, handlers...) }
func Connect(path string, handlers ...fiber.Handler) { app.Connect(path, handlers...) }
func Options(path string, handlers ...fiber.Handler) { app.Options(path, handlers...) }
func Trace(path string, handlers ...fiber.Handler) { app.Trace(path, handlers...) }
func Patch(path string, handlers ...fiber.Handler) { app.Patch(path, handlers...) }
func Static(prefix, root string, config ...fiber.Static) { app.Static(prefix, root, config...) }
func All(path string, handlers ...fiber.Handler) { app.All(path, handlers...) }
func Group(prefix string, handlers ...fiber.Handler) { app.Group(prefix, handlers...) }
func Route(prefix string, fn func(router fiber.Router), name ...string) {
app.Route(prefix, fn, name...)
func App() *fiber.App { return app }
func WrapFunc(h http.HandlerFunc) fiber.Handler { return adaptor.HTTPHandlerFunc(h) }
func Wrap(h http.Handler) fiber.Handler { return adaptor.HTTPHandler(h) }
func Get(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Get(path, handlers, middleware...)
}

func Head(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Head(path, handlers, middleware...)
}

func Post(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Post(path, handlers, middleware...)
}

func Put(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Put(path, handlers, middleware...)
}

func Delete(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Delete(path, handlers, middleware...)
}

func Connect(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Connect(path, handlers, middleware...)
}

func Options(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Options(path, handlers, middleware...)
}

func Trace(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Trace(path, handlers, middleware...)
}

func Patch(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.Patch(path, handlers, middleware...)
}

func All(path string, handlers fiber.Handler, middleware ...fiber.Handler) {
app.All(path, handlers, middleware...)
}

func Group(prefix string, handlers ...fiber.Handler) {
app.Group(prefix, handlers...)
}

func Route(prefix string, fn func(r fiber.Router)) { fn(app.Use(prefix)) }

func Use(args ...any) fiber.Router {
return app.Use(args...)
}
53 changes: 25 additions & 28 deletions core/debug/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,35 @@ import (
"net/http/pprof"

"github.com/felixge/fgprof"
"github.com/gofiber/fiber/v2"

fiber "github.com/gofiber/fiber/v3"
"github.com/pubgo/lava/core/debug"
)

func init() {
debug.Get("/gprof/", debug.Wrap(fgprof.Handler()))
debug.Route("/pprof/", func(r fiber.Router) {
r.Get("", debug.WrapFunc(pprof.Index))
r.Get(":name", func(ctx *fiber.Ctx) error {
name := ctx.Params("name")
switch name {
case "cmdline":
return debug.WrapFunc(pprof.Cmdline)(ctx)
case "profile":
return debug.WrapFunc(pprof.Profile)(ctx)
case "symbol":
return debug.WrapFunc(pprof.Symbol)(ctx)
case "trace":
return debug.WrapFunc(pprof.Trace)(ctx)
case "allocs":
return debug.Wrap(pprof.Handler("allocs"))(ctx)
case "goroutine":
return debug.Wrap(pprof.Handler("goroutine"))(ctx)
case "heap":
return debug.Wrap(pprof.Handler("heap"))(ctx)
case "mutex":
return debug.Wrap(pprof.Handler("mutex"))(ctx)
case "threadcreate":
return debug.Wrap(pprof.Handler("threadcreate"))(ctx)
}
return errors.New("name not found")
})
debug.Get("/pprof/", debug.WrapFunc(pprof.Index))
debug.Get("/pprof/:name", func(ctx fiber.Ctx) error {
name := ctx.Params("name")
switch name {
case "cmdline":
return debug.WrapFunc(pprof.Cmdline)(ctx)
case "profile":
return debug.WrapFunc(pprof.Profile)(ctx)
case "symbol":
return debug.WrapFunc(pprof.Symbol)(ctx)
case "trace":
return debug.WrapFunc(pprof.Trace)(ctx)
case "allocs":
return debug.Wrap(pprof.Handler("allocs"))(ctx)
case "goroutine":
return debug.Wrap(pprof.Handler("goroutine"))(ctx)
case "heap":
return debug.Wrap(pprof.Handler("heap"))(ctx)
case "mutex":
return debug.Wrap(pprof.Handler("mutex"))(ctx)
case "threadcreate":
return debug.Wrap(pprof.Handler("threadcreate"))(ctx)
}
return errors.New("name not found")
})
}
4 changes: 2 additions & 2 deletions core/debug/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package process
import (
"debug/buildinfo"

"github.com/gofiber/fiber/v2"
fiber "github.com/gofiber/fiber/v3"
ps "github.com/keybase/go-ps"
"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/generic"
Expand All @@ -13,7 +13,7 @@ import (
)

func init() {
debug.Get("/process", func(ctx *fiber.Ctx) error {
debug.Get("/process", func(ctx fiber.Ctx) error {
processes := assert.Must1(ps.Processes())
processes1 := generic.Map(processes, func(i int) map[string]any {
p := processes[i]
Expand Down
31 changes: 15 additions & 16 deletions core/debug/statsviz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"

"github.com/arl/statsviz"
"github.com/gofiber/fiber/v2"
fiber "github.com/gofiber/fiber/v3"
"github.com/pubgo/funk/assert"
"github.com/pubgo/lava/core/debug"
"github.com/pubgo/lava/pkg/httputil"
Expand All @@ -14,22 +14,21 @@ import (

func init() {
srv := assert.Exit1(statsviz.NewServer(statsviz.Root("/statsviz")))
debug.Route("/statsviz", func(router fiber.Router) {
router.Use(func(ctx *fiber.Ctx) error {
path := string(ctx.Request().URI().Path())
pathList := strings.Split(path, "/")
if strings.Trim(pathList[len(pathList)-1], "/") == "ws" {
return httputil.HTTPHandler(srv.Ws())(ctx)
}
router := debug.Use("/statsviz")
router.Use(func(ctx fiber.Ctx) error {
path := string(ctx.Request().URI().Path())
pathList := strings.Split(path, "/")
if strings.Trim(pathList[len(pathList)-1], "/") == "ws" {
return httputil.HTTPHandler(srv.Ws())(ctx)
}

return ctx.Next()
})
return ctx.Next()
})

router.Get("/", func(ctx *fiber.Ctx) error {
return httputil.HTTPHandler(srv.Index())(ctx)
})
router.Get("/*", func(ctx *fiber.Ctx) error {
return httputil.HTTPHandler(srv.Index())(ctx)
})
router.Get("/", func(ctx fiber.Ctx) error {
return httputil.HTTPHandler(srv.Index())(ctx)
})
router.Get("/*", func(ctx fiber.Ctx) error {
return httputil.HTTPHandler(srv.Index())(ctx)
})
}
2 changes: 1 addition & 1 deletion core/debug/trace/trace.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package trace

import (
"github.com/gofiber/adaptor/v2"
adaptor "github.com/gofiber/fiber/v3/middleware/adaptor"
"golang.org/x/net/trace"

"github.com/pubgo/lava/core/debug"
Expand Down
29 changes: 14 additions & 15 deletions core/debug/vars/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"expvar"
"fmt"

"github.com/gofiber/fiber/v2"
fiber "github.com/gofiber/fiber/v3"
g "github.com/maragudk/gomponents"
c "github.com/maragudk/gomponents/components"
h "github.com/maragudk/gomponents/html"
Expand All @@ -25,21 +25,20 @@ func init() {
return c.HTML5(c.HTML5Props{Title: "/expvar", Body: nodes})
}

debug.Route("/vars", func(r fiber.Router) {
r.Get("/", func(ctx *fiber.Ctx) error {
ctx.Response().Header.SetContentType(fiber.MIMETextHTMLCharsetUTF8)
var keys []string
expvar.Do(func(kv expvar.KeyValue) {
keys = append(keys, fmt.Sprintf("/debug/vars/%s", kv.Key))
})

return index(keys).Render(ctx)
r := debug.Use("/vars")
r.Get("/", func(ctx fiber.Ctx) error {
ctx.Response().Header.SetContentType(fiber.MIMETextHTMLCharsetUTF8)
var keys []string
expvar.Do(func(kv expvar.KeyValue) {
keys = append(keys, fmt.Sprintf("/debug/vars/%s", kv.Key))
})

r.Get("/:name", func(ctx *fiber.Ctx) error {
name := ctx.Params("name")
ctx.Response().Header.Set("Content-Type", "application/json; charset=utf-8")
return ctx.SendString(expvar.Get(name).String())
})
return index(keys).Render(ctx)
})

r.Get("/:name", func(ctx fiber.Ctx) error {
name := ctx.Params("name")
ctx.Response().Header.Set("Content-Type", "application/json; charset=utf-8")
return ctx.SendString(expvar.Get(name).String())
})
}
2 changes: 1 addition & 1 deletion core/debug/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
rd "runtime/debug"

json "github.com/goccy/go-json"
"github.com/gofiber/adaptor/v2"
adaptor "github.com/gofiber/fiber/v3/middleware/adaptor"
"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/running"

Expand Down
4 changes: 2 additions & 2 deletions core/healthy/aaa.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package healthy

import (
"github.com/gofiber/fiber/v2"
fiber "github.com/gofiber/fiber/v3"
)

type Handler func(req *fiber.Ctx) error
type Handler func(req fiber.Ctx) error
4 changes: 4 additions & 0 deletions core/metrics/_docs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
package metrics

// https://github.com/hashicorp/go-metrics
// https://github.com/VictoriaMetrics/metrics
// github.com/uber-go/tally
// https://github.com/armon/go-metrics
// https://github.com/rcrowley/go-metrics
Loading
Loading