swe

package module
v1.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 17 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CtxKeyLogID string = "ctx_logid"

Functions

func AssignLogID added in v1.0.11

func AssignLogID(ctx *Context)

func CtxLogID added in v1.0.2

func CtxLogID(ctx *Context) string

func CtxValue

func CtxValue[T any](ctx *Context, key any) (ret T, ok bool)

func DecodeForm

func DecodeForm(r *http.Request, ptr any) error

func InitLogID added in v1.0.2

func InitLogID(ctx *Context)

func RenderTime

func RenderTime(ts time.Time) string

func SetDefaultLogLevel

func SetDefaultLogLevel(level LogLevel)

func SetDefaultLogRenderer

func SetDefaultLogRenderer(r LogRenderer)

func SetDefaultLogWriter

func SetDefaultLogWriter(out io.Writer)

Types

type APIServer

type APIServer struct {
	// contains filtered or unexported fields
}

func NewAPIServer

func NewAPIServer() *APIServer

func (*APIServer) RegisterHandler

func (s *APIServer) RegisterHandler(method, path string, handler HandlerFunc, middlewares ...HandlerFunc)

func (*APIServer) ServeHTTP

func (s *APIServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Context

type Context struct {
	Request  *http.Request
	Response http.ResponseWriter
	// contains filtered or unexported fields
}

func (*Context) Get

func (ctx *Context) Get(key any) (any, bool)

func (*Context) Next

func (ctx *Context) Next()

func (*Context) Put

func (ctx *Context) Put(key, value any)

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(apiPrefix string, apiServer *APIServer, fileServer *FileServer) *Engine

func (*Engine) Close added in v1.0.4

func (s *Engine) Close() error

func (*Engine) Serve

func (s *Engine) Serve(addr string)

func (*Engine) ServeHTTP

func (s *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

type FileServer

type FileServer struct {
	// contains filtered or unexported fields
}

func NewFileServer

func NewFileServer(root, tryFile string, forbidDir bool) *FileServer

func (*FileServer) ServeHTTP

func (s *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HandlerFunc

type HandlerFunc func(*Context)

func MakeAPIHandler

func MakeAPIHandler[InType, OutType any](handler func(*Context, *InType) (*OutType, SweError)) HandlerFunc

type LogLevel

type LogLevel int
const (
	LOG_DEBUG LogLevel = iota
	LOG_INFO
	LOG_WARN
	LOG_ERROR
)

func (LogLevel) String

func (l LogLevel) String() string

type LogRenderer

type LogRenderer interface {
	RenderLog(ctx *Context, level LogLevel, ts time.Time, file string, line int, content string) string
}

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func CtxLogger

func CtxLogger(ctx *Context) *Logger

func (*Logger) Debug

func (l *Logger) Debug(format string, params ...any)

func (*Logger) Error

func (l *Logger) Error(format string, params ...any)

func (*Logger) Info

func (l *Logger) Info(format string, params ...any)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

func (*Logger) SetRenderer

func (l *Logger) SetRenderer(r LogRenderer)

func (*Logger) SetWriter

func (l *Logger) SetWriter(out io.Writer)

func (*Logger) Warn

func (l *Logger) Warn(format string, params ...any)

type SweError added in v1.0.3

type SweError interface {
	Err() error
	Code() int
}

func Error added in v1.0.3

func Error(code int, err error) SweError

type Validator added in v1.0.9

type Validator interface {
	Validate(ctx *Context) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL