Skip to content

Commit

Permalink
Merge branch 'refs/heads/v2-feature-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
dobyte committed Jul 29, 2024
2 parents 0f73035 + c8d50c8 commit ea38e4e
Show file tree
Hide file tree
Showing 20 changed files with 1,895 additions and 123 deletions.
6 changes: 3 additions & 3 deletions cluster/gate/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (p *proxy) deliver(ctx context.Context, cid, uid int64, message []byte) {
}

if mode.IsDebugMode() {
log.Debugf("deliver message, cid: %d uid: %d route: %d buffer: %s", cid, uid, msg.Route, string(msg.Buffer))
log.Debugf("deliver message, cid: %d uid: %d seq: %d route: %d buffer: %s", cid, uid, msg.Seq, msg.Route, string(msg.Buffer))
}

if err = p.nodeLinker.Deliver(ctx, &link.DeliverArgs{
Expand All @@ -81,9 +81,9 @@ func (p *proxy) deliver(ctx context.Context, cid, uid int64, message []byte) {
}); err != nil {
switch {
case errors.Is(err, errors.ErrNotFoundRoute):
log.Debugf("deliver message failed, cid: %d uid: %d route: %d err: %v", cid, uid, msg.Route, err)
log.Debugf("deliver message failed, cid: %d uid: %d seq: %d route: %d err: %v", cid, uid, msg.Seq, msg.Route, err)
default:
log.Errorf("deliver message failed, cid: %d uid: %d route: %d err: %v", cid, uid, msg.Route, err)
log.Errorf("deliver message failed, cid: %d uid: %d seq: %d route: %d err: %v", cid, uid, msg.Seq, msg.Route, err)
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions component/http/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package http

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

type Resp struct {
Code int `json:"code"` // 响应码
Data any `json:"data,omitempty"` // 响应数据
}

type Context interface {
fiber.Ctx
// CTX 获取fiber.Ctx
CTX() fiber.Ctx
// Proxy 获取代理API
Proxy() *Proxy
// Failure 失败响应
Failure(rst any) error
// Success 成功响应
Success(data ...any) error
}

type context struct {
fiber.Ctx
proxy *Proxy
}

// CTX 获取fiber.Ctx
func (c *context) CTX() fiber.Ctx {
return c.Ctx
}

// Proxy 代理API
func (c *context) Proxy() *Proxy {
return c.proxy
}

// Failure 失败响应
func (c *context) Failure(rst any) error {
switch v := rst.(type) {
case error:
return c.JSON(&Resp{Code: codes.Convert(v).Code()})
case *codes.Code:
return c.JSON(&Resp{Code: v.Code()})
default:
return c.JSON(&Resp{Code: codes.Unknown.Code()})
}
}

// Success 成功响应
func (c *context) Success(data ...any) error {
if len(data) > 0 {
return c.JSON(&Resp{Code: codes.OK.Code(), Data: data[0]})
} else {
return c.JSON(&Resp{Code: codes.OK.Code()})
}
}
45 changes: 27 additions & 18 deletions component/http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,51 @@ go 1.22

require (
github.com/dobyte/due/v2 v2.1.0
github.com/gin-gonic/gin v1.10.0
github.com/go-openapi/runtime v0.28.0
github.com/gofiber/fiber/v3 v3.0.0-beta.3
)

require (
github.com/BurntSushi/toml v1.2.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.mongodb.org/mongo-driver v1.16.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
Loading

0 comments on commit ea38e4e

Please sign in to comment.