feat: bootstrap reusable GoOmni framework
This commit is contained in:
67
omni.go
Normal file
67
omni.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package omni
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.yuntuo.hk/k2safe/go-omni/app"
|
||||
"git.yuntuo.hk/k2safe/go-omni/auth"
|
||||
"git.yuntuo.hk/k2safe/go-omni/config"
|
||||
apierrors "git.yuntuo.hk/k2safe/go-omni/errors"
|
||||
"git.yuntuo.hk/k2safe/go-omni/httpx"
|
||||
"git.yuntuo.hk/k2safe/go-omni/logx"
|
||||
"git.yuntuo.hk/k2safe/go-omni/response"
|
||||
)
|
||||
|
||||
type App = app.App
|
||||
type RouterGroup = app.RouterGroup
|
||||
type Principal = auth.Principal
|
||||
type Authenticator = auth.Authenticator
|
||||
type Context = httpx.Context
|
||||
type Handler = httpx.Handler
|
||||
type Middleware = httpx.Middleware
|
||||
type Router = httpx.Router
|
||||
type HTTPRouterGroup = httpx.RouterGroup
|
||||
type APIError = apierrors.APIError
|
||||
type Config = config.Config
|
||||
type Option = config.Option
|
||||
type Response = response.Response
|
||||
type LogConfig = logx.Config
|
||||
type Logger = logx.Logger
|
||||
|
||||
func New(options ...Option) *App { return app.New(options...) }
|
||||
|
||||
func NewWithRouter(router Router, options ...Option) *App {
|
||||
return app.NewWithRouter(router, options...)
|
||||
}
|
||||
|
||||
func WithMode(mode string) Option { return config.WithMode(mode) }
|
||||
|
||||
func WithRequestIDHeader(header string) Option { return config.WithRequestIDHeader(header) }
|
||||
|
||||
func WithLogger(enabled bool) Option { return config.WithLogger(enabled) }
|
||||
|
||||
func WithConfig(settings Config) Option { return config.WithConfig(settings) }
|
||||
|
||||
func WithLogConfig(settings LogConfig) Option { return config.WithLogConfig(settings) }
|
||||
|
||||
func WithShutdownTimeout(timeout time.Duration) Option { return config.WithShutdownTimeout(timeout) }
|
||||
|
||||
func LoadConfig(prefix string) (Config, error) { return config.LoadFromEnv(prefix) }
|
||||
|
||||
func SetupLogger(cfg LogConfig) (func() error, error) { return logx.Setup(cfg) }
|
||||
|
||||
func NewError(status int, code, message string) *APIError {
|
||||
return apierrors.New(status, code, message)
|
||||
}
|
||||
|
||||
func BadRequest(code, message string) *APIError { return apierrors.BadRequest(code, message) }
|
||||
|
||||
func Unauthorized(code, message string) *APIError { return apierrors.Unauthorized(code, message) }
|
||||
|
||||
func Forbidden(code, message string) *APIError { return apierrors.Forbidden(code, message) }
|
||||
|
||||
func NotFound(code, message string) *APIError { return apierrors.NotFound(code, message) }
|
||||
|
||||
func Internal(cause error) *APIError { return apierrors.Internal(cause) }
|
||||
|
||||
func PrincipalFromContext(ctx *Context) (Principal, bool) { return auth.FromContext(ctx) }
|
||||
Reference in New Issue
Block a user