Compare commits
No commits in common. "main" and "v0.0.11" have entirely different histories.
15
app.go
15
app.go
|
@ -109,14 +109,10 @@ func (s *Service) injectVars(v any) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fieldType := refType.Field(i)
|
fieldType := refType.Field(i)
|
||||||
if !(fieldType.Type.Kind() != reflect.Ptr || fieldType.Type.Kind() != reflect.Interface) {
|
if fieldType.Type.Kind() != reflect.Ptr {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, rv := range s.refValues {
|
for _, rv := range s.refValues {
|
||||||
if fieldType.Type.Kind() == reflect.Interface && rv.Type().Implements(fieldType.Type) {
|
|
||||||
refValue.Field(i).Set(rv)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if fieldType.Type == rv.Type() {
|
if fieldType.Type == rv.Type() {
|
||||||
refValue.Field(i).Set(rv)
|
refValue.Field(i).Set(rv)
|
||||||
break
|
break
|
||||||
|
@ -127,10 +123,7 @@ func (s *Service) injectVars(v any) {
|
||||||
|
|
||||||
func (s *Service) preStart(ctx context.Context) (err error) {
|
func (s *Service) preStart(ctx context.Context) (err error) {
|
||||||
s.Logger().Info(ctx, "starting")
|
s.Logger().Info(ctx, "starting")
|
||||||
s.refValues = append(s.refValues, s.opts.injectVars...)
|
|
||||||
s.refValues = append(s.refValues, reflect.ValueOf(s.Logger()))
|
|
||||||
for _, ptr := range s.opts.servers {
|
for _, ptr := range s.opts.servers {
|
||||||
s.injectVars(ptr)
|
|
||||||
s.refValues = append(s.refValues, reflect.ValueOf(ptr))
|
s.refValues = append(s.refValues, reflect.ValueOf(ptr))
|
||||||
}
|
}
|
||||||
if s.opts.registry != nil {
|
if s.opts.registry != nil {
|
||||||
|
@ -192,7 +185,7 @@ func (s *Service) preStart(ctx context.Context) (err error) {
|
||||||
o.Context = ctx
|
o.Context = ctx
|
||||||
o.TTL = s.opts.registrarTimeout
|
o.TTL = s.opts.registrarTimeout
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
s.Logger().Warnf(ctx, "service register error: %v", err)
|
s.Logger().Warn(ctx, "service register error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,14 +206,14 @@ func (s *Service) preStop() (err error) {
|
||||||
}()
|
}()
|
||||||
for _, srv := range s.opts.servers {
|
for _, srv := range s.opts.servers {
|
||||||
if err = srv.Stop(ctx); err != nil {
|
if err = srv.Stop(ctx); err != nil {
|
||||||
s.Logger().Warnf(ctx, "server stop error: %v", err)
|
s.Logger().Warn(ctx, "server stop error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.opts.registry != nil {
|
if s.opts.registry != nil {
|
||||||
if err = s.opts.registry.Deregister(s.service, func(o *registry.DeregisterOptions) {
|
if err = s.opts.registry.Deregister(s.service, func(o *registry.DeregisterOptions) {
|
||||||
o.Context = ctx
|
o.Context = ctx
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
s.Logger().Warnf(ctx, "server deregister error: %v", err)
|
s.Logger().Warn(ctx, "server deregister error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.Logger().Info(ctx, "stopped")
|
s.Logger().Info(ctx, "stopped")
|
||||||
|
|
|
@ -57,16 +57,9 @@ func WithAllow(paths ...string) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithClaims(claims any) Option {
|
func WithClaims(claims reflect.Type) Option {
|
||||||
return func(o *options) {
|
return func(o *options) {
|
||||||
if tv, ok := claims.(reflect.Type); ok {
|
o.claims = claims
|
||||||
o.claims = tv
|
|
||||||
} else {
|
|
||||||
o.claims = reflect.TypeOf(claims)
|
|
||||||
if o.claims.Kind() == reflect.Ptr {
|
|
||||||
o.claims = o.claims.Elem()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
options.go
10
options.go
|
@ -3,7 +3,6 @@ package aeus
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"maps"
|
"maps"
|
||||||
"reflect"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.nobla.cn/golang/aeus/pkg/logger"
|
"git.nobla.cn/golang/aeus/pkg/logger"
|
||||||
|
@ -25,7 +24,6 @@ type options struct {
|
||||||
registry registry.Registry
|
registry registry.Registry
|
||||||
serviceLoader ServiceLoader
|
serviceLoader ServiceLoader
|
||||||
stopTimeout time.Duration
|
stopTimeout time.Duration
|
||||||
injectVars []reflect.Value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithName(name string) Option {
|
func WithName(name string) Option {
|
||||||
|
@ -79,14 +77,6 @@ func WithDebug(debug bool) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithInjectVars(vars ...any) Option {
|
|
||||||
return func(o *options) {
|
|
||||||
for _, v := range vars {
|
|
||||||
o.injectVars = append(o.injectVars, reflect.ValueOf(v))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithServiceLoader(loader ServiceLoader) Option {
|
func WithServiceLoader(loader ServiceLoader) Option {
|
||||||
return func(o *options) {
|
return func(o *options) {
|
||||||
o.serviceLoader = loader
|
o.serviceLoader = loader
|
||||||
|
|
|
@ -4,8 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.nobla.cn/golang/aeus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type redisCache struct {
|
type redisCache struct {
|
||||||
|
@ -59,12 +57,7 @@ func (c *redisCache) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCache(opts ...Option) *redisCache {
|
func NewCache(opts ...Option) *redisCache {
|
||||||
cache := &redisCache{
|
return &redisCache{
|
||||||
opts: newOptions(opts...),
|
opts: newOptions(opts...),
|
||||||
}
|
}
|
||||||
app := aeus.FromContext(cache.opts.context)
|
|
||||||
if app != nil {
|
|
||||||
cache.opts.prefix = app.Name() + ":" + cache.opts.prefix
|
|
||||||
}
|
|
||||||
return cache
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
package redis
|
package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
options struct {
|
options struct {
|
||||||
context context.Context
|
client *redis.Client
|
||||||
client *redis.Client
|
prefix string
|
||||||
prefix string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Option func(*options)
|
Option func(*options)
|
||||||
|
@ -22,12 +19,6 @@ func WithClient(client *redis.Client) Option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithContext(ctx context.Context) Option {
|
|
||||||
return func(o *options) {
|
|
||||||
o.context = ctx
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithPrefix(prefix string) Option {
|
func WithPrefix(prefix string) Option {
|
||||||
return func(o *options) {
|
return func(o *options) {
|
||||||
o.prefix = prefix
|
o.prefix = prefix
|
||||||
|
|
|
@ -3,7 +3,6 @@ package logger
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -11,56 +10,32 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log = NewLogger(slog.New(
|
log = NewLogger(slog.Default())
|
||||||
slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
|
||||||
Level: slog.LevelDebug,
|
|
||||||
}),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
Debug(ctx context.Context, format string, args ...any) //Structured context as loosely typed key-value pairs.
|
Debug(ctx context.Context, format string, args ...any)
|
||||||
Debugf(ctx context.Context, format string, args ...any)
|
|
||||||
Info(ctx context.Context, format string, args ...any)
|
Info(ctx context.Context, format string, args ...any)
|
||||||
Infof(ctx context.Context, format string, args ...any)
|
|
||||||
Warn(ctx context.Context, format string, args ...any)
|
Warn(ctx context.Context, format string, args ...any)
|
||||||
Warnf(ctx context.Context, format string, args ...any)
|
|
||||||
Error(ctx context.Context, format string, args ...any)
|
Error(ctx context.Context, format string, args ...any)
|
||||||
Errorf(ctx context.Context, format string, args ...any)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debug(ctx context.Context, format string, args ...any) {
|
func Debug(ctx context.Context, format string, args ...any) {
|
||||||
log.Debug(ctx, format, args...)
|
log.Debug(ctx, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debugf(ctx context.Context, format string, args ...any) {
|
|
||||||
log.Debugf(ctx, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Info(ctx context.Context, format string, args ...any) {
|
func Info(ctx context.Context, format string, args ...any) {
|
||||||
log.Info(ctx, format, args...)
|
log.Debug(ctx, format, args...)
|
||||||
}
|
|
||||||
|
|
||||||
func Infof(ctx context.Context, format string, args ...any) {
|
|
||||||
log.Infof(ctx, format, args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Warn(ctx context.Context, format string, args ...any) {
|
func Warn(ctx context.Context, format string, args ...any) {
|
||||||
log.Warn(ctx, format, args...)
|
log.Debug(ctx, format, args...)
|
||||||
}
|
|
||||||
|
|
||||||
func Warnf(ctx context.Context, format string, args ...any) {
|
|
||||||
log.Warnf(ctx, format, args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Error(ctx context.Context, format string, args ...any) {
|
func Error(ctx context.Context, format string, args ...any) {
|
||||||
log.Debug(ctx, format, args...)
|
log.Debug(ctx, format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Errorf(ctx context.Context, format string, args ...any) {
|
|
||||||
log.Errorf(ctx, format, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Default() Logger {
|
func Default() Logger {
|
||||||
return log
|
return log
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,34 +11,18 @@ type logger struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) Debug(ctx context.Context, msg string, args ...any) {
|
func (l *logger) Debug(ctx context.Context, msg string, args ...any) {
|
||||||
l.log.DebugContext(ctx, msg, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logger) Debugf(ctx context.Context, msg string, args ...any) {
|
|
||||||
l.log.DebugContext(ctx, fmt.Sprintf(msg, args...))
|
l.log.DebugContext(ctx, fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) Info(ctx context.Context, msg string, args ...any) {
|
func (l *logger) Info(ctx context.Context, msg string, args ...any) {
|
||||||
l.log.InfoContext(ctx, msg, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logger) Infof(ctx context.Context, msg string, args ...any) {
|
|
||||||
l.log.InfoContext(ctx, fmt.Sprintf(msg, args...))
|
l.log.InfoContext(ctx, fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) Warn(ctx context.Context, msg string, args ...any) {
|
func (l *logger) Warn(ctx context.Context, msg string, args ...any) {
|
||||||
l.log.WarnContext(ctx, msg, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logger) Warnf(ctx context.Context, msg string, args ...any) {
|
|
||||||
l.log.WarnContext(ctx, fmt.Sprintf(msg, args...))
|
l.log.WarnContext(ctx, fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *logger) Error(ctx context.Context, msg string, args ...any) {
|
func (l *logger) Error(ctx context.Context, msg string, args ...any) {
|
||||||
l.log.ErrorContext(ctx, msg, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *logger) Errorf(ctx context.Context, msg string, args ...any) {
|
|
||||||
l.log.ErrorContext(ctx, fmt.Sprintf(msg, args...))
|
l.log.ErrorContext(ctx, fmt.Sprintf(msg, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ type Server struct {
|
||||||
uri *url.URL
|
uri *url.URL
|
||||||
exitFlag int32
|
exitFlag int32
|
||||||
middleware []middleware.Middleware
|
middleware []middleware.Middleware
|
||||||
Logger logger.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svr *Server) Use(middlewares ...middleware.Middleware) {
|
func (svr *Server) Use(middlewares ...middleware.Middleware) {
|
||||||
|
@ -135,7 +134,7 @@ func (s *Server) execute(ctx *Context, frame *Frame) (err error) {
|
||||||
func (svr *Server) nextSequence() int64 {
|
func (svr *Server) nextSequence() int64 {
|
||||||
svr.sequenceLocker.Lock()
|
svr.sequenceLocker.Lock()
|
||||||
defer svr.sequenceLocker.Unlock()
|
defer svr.sequenceLocker.Unlock()
|
||||||
if svr.sequence == math.MaxInt64 {
|
if svr.sequence >= math.MaxInt64 {
|
||||||
svr.sequence = 1
|
svr.sequence = 1
|
||||||
}
|
}
|
||||||
svr.sequence++
|
svr.sequence++
|
||||||
|
@ -209,16 +208,10 @@ func (s *Server) serve() (err error) {
|
||||||
|
|
||||||
func (s *Server) Start(ctx context.Context) (err error) {
|
func (s *Server) Start(ctx context.Context) (err error) {
|
||||||
s.ctx = ctx
|
s.ctx = ctx
|
||||||
if s.opts.logger != nil {
|
|
||||||
s.Logger = s.opts.logger
|
|
||||||
}
|
|
||||||
if s.Logger == nil {
|
|
||||||
s.Logger = logger.Default()
|
|
||||||
}
|
|
||||||
if err = s.createListener(); err != nil {
|
if err = s.createListener(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Logger.Infof(ctx, "cli server listen on: %s", s.uri.Host)
|
s.opts.logger.Info(ctx, "cli server listen on: %s", s.uri.Host)
|
||||||
s.Handle("/help", "Display help information", func(ctx *Context) (err error) {
|
s.Handle("/help", "Display help information", func(ctx *Context) (err error) {
|
||||||
return ctx.Success(s.router.String())
|
return ctx.Success(s.router.String())
|
||||||
})
|
})
|
||||||
|
@ -231,9 +224,7 @@ func (s *Server) Stop(ctx context.Context) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.listener != nil {
|
if s.listener != nil {
|
||||||
if err = s.listener.Close(); err != nil {
|
err = s.listener.Close()
|
||||||
s.Logger.Warnf(ctx, "cli listener close error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
s.ctxMap.Range(func(key, value any) bool {
|
s.ctxMap.Range(func(key, value any) bool {
|
||||||
if ctx, ok := value.(*Context); ok {
|
if ctx, ok := value.(*Context); ok {
|
||||||
|
@ -241,7 +232,6 @@ func (s *Server) Stop(ctx context.Context) (err error) {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
s.Logger.Info(ctx, "cli server stopped")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,6 +240,7 @@ func New(cbs ...Option) *Server {
|
||||||
opts: &options{
|
opts: &options{
|
||||||
network: "tcp",
|
network: "tcp",
|
||||||
address: ":0",
|
address: ":0",
|
||||||
|
logger: logger.Default(),
|
||||||
},
|
},
|
||||||
uri: &url.URL{Scheme: "cli"},
|
uri: &url.URL{Scheme: "cli"},
|
||||||
router: newRouter(""),
|
router: newRouter(""),
|
||||||
|
|
|
@ -25,7 +25,6 @@ type Server struct {
|
||||||
serve *grpc.Server
|
serve *grpc.Server
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
middlewares []middleware.Middleware
|
middlewares []middleware.Middleware
|
||||||
Logger logger.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) createListener() (err error) {
|
func (s *Server) createListener() (err error) {
|
||||||
|
@ -108,16 +107,11 @@ func (s *Server) Use(middlewares ...middleware.Middleware) {
|
||||||
|
|
||||||
func (s *Server) Start(ctx context.Context) (err error) {
|
func (s *Server) Start(ctx context.Context) (err error) {
|
||||||
s.ctx = ctx
|
s.ctx = ctx
|
||||||
if s.opts.logger != nil {
|
|
||||||
s.Logger = s.opts.logger
|
|
||||||
}
|
|
||||||
if s.Logger == nil {
|
|
||||||
s.Logger = logger.Default()
|
|
||||||
}
|
|
||||||
if err = s.createListener(); err != nil {
|
if err = s.createListener(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Logger.Infof(ctx, "grpc server listen on: %s", s.uri.Host)
|
s.opts.logger.Info(ctx, "grpc server listen on: %s", s.uri.Host)
|
||||||
|
|
||||||
reflection.Register(s.serve)
|
reflection.Register(s.serve)
|
||||||
s.serve.Serve(s.listener)
|
s.serve.Serve(s.listener)
|
||||||
return
|
return
|
||||||
|
@ -136,7 +130,7 @@ func (s *Server) RegisterService(sd *grpc.ServiceDesc, ss any) {
|
||||||
|
|
||||||
func (s *Server) Stop(ctx context.Context) (err error) {
|
func (s *Server) Stop(ctx context.Context) (err error) {
|
||||||
s.serve.GracefulStop()
|
s.serve.GracefulStop()
|
||||||
s.Logger.Infof(s.ctx, "grpc server stopped")
|
s.opts.logger.Info(s.ctx, "grpc server stopped")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +138,7 @@ func New(cbs ...Option) *Server {
|
||||||
svr := &Server{
|
svr := &Server{
|
||||||
opts: &options{
|
opts: &options{
|
||||||
network: "tcp",
|
network: "tcp",
|
||||||
|
logger: logger.Default(),
|
||||||
grpcOpts: make([]grpc.ServerOption, 0, 10),
|
grpcOpts: make([]grpc.ServerOption, 0, 10),
|
||||||
},
|
},
|
||||||
uri: &url.URL{
|
uri: &url.URL{
|
||||||
|
|
|
@ -36,7 +36,6 @@ type Server struct {
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
fs *filesystem
|
fs *filesystem
|
||||||
middlewares []middleware.Middleware
|
middlewares []middleware.Middleware
|
||||||
Logger logger.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Endpoint(ctx context.Context) (string, error) {
|
func (s *Server) Endpoint(ctx context.Context) (string, error) {
|
||||||
|
@ -157,6 +156,7 @@ func (s *Server) staticHandle(ctx *gin.Context, fp http.File) {
|
||||||
}
|
}
|
||||||
http.ServeContent(ctx.Writer, ctx.Request, path.Base(uri), s.fs.modtime, fp)
|
http.ServeContent(ctx.Writer, ctx.Request, path.Base(uri), s.fs.modtime, fp)
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) notFoundHandle(ctx *gin.Context) {
|
func (s *Server) notFoundHandle(ctx *gin.Context) {
|
||||||
|
@ -255,12 +255,6 @@ func (s *Server) Start(ctx context.Context) (err error) {
|
||||||
Addr: s.opts.address,
|
Addr: s.opts.address,
|
||||||
Handler: s.engine,
|
Handler: s.engine,
|
||||||
}
|
}
|
||||||
if s.opts.logger != nil {
|
|
||||||
s.Logger = s.opts.logger
|
|
||||||
}
|
|
||||||
if s.Logger == nil {
|
|
||||||
s.Logger = logger.Default()
|
|
||||||
}
|
|
||||||
s.ctx = ctx
|
s.ctx = ctx
|
||||||
if s.opts.debug {
|
if s.opts.debug {
|
||||||
s.engine.Handle(http.MethodGet, "/debug/pprof/", s.wrapHandle(pprof.Index))
|
s.engine.Handle(http.MethodGet, "/debug/pprof/", s.wrapHandle(pprof.Index))
|
||||||
|
@ -277,7 +271,7 @@ func (s *Server) Start(ctx context.Context) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.engine.NoRoute(s.notFoundHandle)
|
s.engine.NoRoute(s.notFoundHandle)
|
||||||
s.Logger.Infof(ctx, "http server listen on: %s", s.uri.Host)
|
s.opts.logger.Info(ctx, "http server listen on: %s", s.uri.Host)
|
||||||
if s.opts.certFile != "" && s.opts.keyFile != "" {
|
if s.opts.certFile != "" && s.opts.keyFile != "" {
|
||||||
s.uri.Scheme = "https"
|
s.uri.Scheme = "https"
|
||||||
err = s.serve.ServeTLS(s.listener, s.opts.certFile, s.opts.keyFile)
|
err = s.serve.ServeTLS(s.listener, s.opts.certFile, s.opts.keyFile)
|
||||||
|
@ -292,7 +286,7 @@ func (s *Server) Start(ctx context.Context) (err error) {
|
||||||
|
|
||||||
func (s *Server) Stop(ctx context.Context) (err error) {
|
func (s *Server) Stop(ctx context.Context) (err error) {
|
||||||
err = s.serve.Shutdown(ctx)
|
err = s.serve.Shutdown(ctx)
|
||||||
s.Logger.Infof(ctx, "http server stopped")
|
s.opts.logger.Info(ctx, "http server stopped")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,6 +295,7 @@ func New(cbs ...Option) *Server {
|
||||||
uri: &url.URL{Scheme: "http"},
|
uri: &url.URL{Scheme: "http"},
|
||||||
opts: &options{
|
opts: &options{
|
||||||
network: "tcp",
|
network: "tcp",
|
||||||
|
logger: logger.Default(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
port, _ := strconv.Atoi(os.Getenv("HTTP_PORT"))
|
port, _ := strconv.Atoi(os.Getenv("HTTP_PORT"))
|
||||||
|
|
Loading…
Reference in New Issue