97 lines
3.3 KiB
Go
97 lines
3.3 KiB
Go
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/metrics"
|
|
"git.yuntuo.hk/k2safe/go-omni/response"
|
|
)
|
|
|
|
type App = app.App
|
|
type Runner = app.Runner
|
|
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 TLSConfig = config.TLSConfig
|
|
type HTTPConfig = config.HTTPConfig
|
|
type Option = config.Option
|
|
type Response = response.Response
|
|
type LogConfig = logx.Config
|
|
type Logger = logx.Logger
|
|
type Metrics = metrics.Metrics
|
|
|
|
const (
|
|
TransportNetHTTP = config.TransportNetHTTP
|
|
TransportNative = config.TransportNative
|
|
TransportHTTP2 = config.TransportHTTP2
|
|
)
|
|
|
|
func New(options ...Option) *App { return app.New(options...) }
|
|
|
|
func NewWithRouter(router Router, options ...Option) *App {
|
|
return app.NewWithRouter(router, options...)
|
|
}
|
|
|
|
func WithRequestIDHeader(header string) Option { return config.WithRequestIDHeader(header) }
|
|
|
|
func WithLogger(enabled bool) Option { return config.WithLogger(enabled) }
|
|
|
|
func WithErrors(catalog apierrors.Catalog) Option { return config.WithErrors(catalog) }
|
|
|
|
func WithResponse(settings response.Config) Option { return config.WithResponse(settings) }
|
|
|
|
func WithResponseEncoder(encoder response.Encoder) Option { return config.WithResponseEncoder(encoder) }
|
|
|
|
func WithSlowRequestThreshold(threshold time.Duration) Option {
|
|
return config.WithSlowRequestThreshold(threshold)
|
|
}
|
|
|
|
func WithTrustedProxies(proxies ...string) Option { return config.WithTrustedProxies(proxies...) }
|
|
|
|
func WithConfig(settings Config) Option { return config.WithConfig(settings) }
|
|
|
|
func WithTransport(name string) Option { return config.WithTransport(name) }
|
|
|
|
func WithHTTPConfig(settings HTTPConfig) Option { return config.WithHTTPConfig(settings) }
|
|
|
|
func WithTLS(certFile, keyFile string) Option { return config.WithTLS(certFile, keyFile) }
|
|
|
|
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 NewMetrics() *Metrics { return metrics.New() }
|
|
|
|
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) }
|