This commit is contained in:
fcl 2025-06-23 17:20:10 +08:00
parent 908931bc01
commit c027ef22bc
5 changed files with 24 additions and 7 deletions

11
app.go
View File

@ -6,6 +6,7 @@ import (
"os/signal" "os/signal"
"reflect" "reflect"
"runtime" "runtime"
"strconv"
"sync/atomic" "sync/atomic"
"syscall" "syscall"
"time" "time"
@ -35,12 +36,19 @@ func (s *Service) Name() string {
} }
func (s *Service) Debug() bool { func (s *Service) Debug() bool {
if s.opts != nil {
return s.opts.debug
}
return false return false
} }
func (s *Service) Version() string { func (s *Service) Version() string {
return s.opts.version if s.opts != nil {
return s.opts.version
}
return ""
} }
func (s *Service) Metadata() map[string]string { func (s *Service) Metadata() map[string]string {
if s.service == nil { if s.service == nil {
return nil return nil
@ -255,6 +263,7 @@ func New(cbs ...Option) *Service {
registrarTimeout: time.Second * 30, registrarTimeout: time.Second * 30,
}, },
} }
s.opts.debug, _ = strconv.ParseBool("AEUS_DEBUG")
s.opts.metadata = make(map[string]string) s.opts.metadata = make(map[string]string)
for _, cb := range cbs { for _, cb := range cbs {
cb(s.opts) cb(s.opts)

View File

@ -108,9 +108,7 @@ func JWT(keyFunc jwt.Keyfunc, cbs ...Option) middleware.Middleware {
return err return err
} }
} }
if strings.HasPrefix(token, bearerWord) { token, _ = strings.CutPrefix(token, bearerWord)
token = strings.TrimPrefix(token, bearerWord)
}
var ( var (
ti *jwt.Token ti *jwt.Token
) )

View File

@ -2,6 +2,7 @@ package aeus
import ( import (
"context" "context"
"maps"
"time" "time"
"git.nobla.cn/golang/aeus/pkg/logger" "git.nobla.cn/golang/aeus/pkg/logger"
@ -18,6 +19,7 @@ type options struct {
servers []Server servers []Server
endpoints []string endpoints []string
scope Scope scope Scope
debug bool
registrarTimeout time.Duration registrarTimeout time.Duration
registry registry.Registry registry registry.Registry
serviceLoader ServiceLoader serviceLoader ServiceLoader
@ -41,9 +43,7 @@ func WithMetadata(metadata map[string]string) Option {
if o.metadata == nil { if o.metadata == nil {
o.metadata = make(map[string]string) o.metadata = make(map[string]string)
} }
for k, v := range metadata { maps.Copy(o.metadata, metadata)
o.metadata[k] = v
}
} }
} }
@ -71,6 +71,12 @@ func WithScope(scope Scope) Option {
} }
} }
func WithDebug(debug bool) Option {
return func(o *options) {
o.debug = debug
}
}
func WithServiceLoader(loader ServiceLoader) Option { func WithServiceLoader(loader ServiceLoader) Option {
return func(o *options) { return func(o *options) {
o.serviceLoader = loader o.serviceLoader = loader

View File

@ -22,6 +22,10 @@ func (c *Context) Context() context.Context {
return c.ctx.Request.Context() return c.ctx.Request.Context()
} }
func (c *Context) Gin() *gin.Context {
return c.ctx
}
func (c *Context) Request() *http.Request { func (c *Context) Request() *http.Request {
return c.ctx.Request return c.ctx.Request
} }