mrserver

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ListenTypeSock = "sock"
	ListenTypePort = "port"
)

Variables

This section is empty.

Functions

func DefaultHttpErrorOverrideFunc added in v0.10.0

func DefaultHttpErrorOverrideFunc(err *mrerr.AppError) (int, *mrerr.AppError)

DefaultHttpErrorOverrideFunc - only for: 401, 403, 404, 418, 5XX

func HandlerGetHealth added in v0.9.6

func HandlerGetHealth() func(w http.ResponseWriter, r *http.Request)

func HandlerGetStatusOKAsJson added in v0.9.6

func HandlerGetStatusOKAsJson() func(w http.ResponseWriter, r *http.Request)

func HandlerGetStructAsJson added in v0.9.6

func HandlerGetStructAsJson(data any, status int) (func(w http.ResponseWriter, r *http.Request), error)

func PrepareAppToStart added in v0.13.0

func PrepareAppToStart(ctx context.Context) (execute func() error, interrupt func(error))

Types

type CacheableResponseWriter added in v0.14.0

type CacheableResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewCacheableResponseWriter added in v0.14.0

func NewCacheableResponseWriter(w http.ResponseWriter) *CacheableResponseWriter

func (*CacheableResponseWriter) Body added in v0.14.0

func (w *CacheableResponseWriter) Body() []byte

func (*CacheableResponseWriter) StatusCode added in v0.14.0

func (w *CacheableResponseWriter) StatusCode() int

func (*CacheableResponseWriter) Write added in v0.14.0

func (w *CacheableResponseWriter) Write(buf []byte) (int, error)

func (*CacheableResponseWriter) WriteHeader added in v0.14.0

func (w *CacheableResponseWriter) WriteHeader(statusCode int)

type ErrorResponseSender added in v0.10.0

type ErrorResponseSender interface {
	SendError(w http.ResponseWriter, r *http.Request, err error)
}

type FileResponseSender added in v0.10.0

type FileResponseSender interface {
	ResponseSender
	SendFile(ctx context.Context, w http.ResponseWriter, file mrtype.File) error
	SendAttachmentFile(ctx context.Context, w http.ResponseWriter, file mrtype.File) error
}

type HttpController added in v0.10.0

type HttpController interface {
	Handlers() []HttpHandler
}

type HttpErrorOverrideFunc added in v0.10.0

type HttpErrorOverrideFunc func(err *mrerr.AppError) (int, *mrerr.AppError)

type HttpHandler added in v0.10.0

type HttpHandler struct {
	Method     string
	URL        string
	Permission string
	Func       HttpHandlerFunc
}

type HttpHandlerAdapterFunc added in v0.10.0

type HttpHandlerAdapterFunc func(next HttpHandlerFunc) http.HandlerFunc

func NewMiddlewareHttpHandlerAdapter added in v0.13.0

func NewMiddlewareHttpHandlerAdapter(s ErrorResponseSender) (HttpHandlerAdapterFunc, error)

type HttpHandlerFunc added in v0.10.0

type HttpHandlerFunc func(w http.ResponseWriter, r *http.Request) error

func MiddlewareCheckAccess added in v0.10.0

func MiddlewareCheckAccess(
	section mrperms.AppSection,
	access mrperms.AccessControl,
	permission string,
	next HttpHandlerFunc,
) HttpHandlerFunc

func MiddlewareIdempotency added in v0.14.0

func MiddlewareIdempotency(provider mridempotency.Provider, sender ResponseSender, next HttpHandlerFunc) HttpHandlerFunc

type HttpMiddleware added in v0.10.0

type HttpMiddleware interface {
	Middleware(next http.Handler) http.Handler
}

func MiddlewareGeneral added in v0.13.0

func MiddlewareGeneral(tr *mrlang.Translator) HttpMiddleware

type HttpMiddlewareFunc added in v0.10.0

type HttpMiddlewareFunc func(next http.Handler) http.Handler

func (HttpMiddlewareFunc) Middleware added in v0.10.0

func (f HttpMiddlewareFunc) Middleware(next http.Handler) http.Handler

type HttpRouter added in v0.10.0

type HttpRouter interface {
	RegisterMiddleware(handlers ...HttpMiddleware)
	Register(controllers ...HttpController)
	HandlerFunc(method, path string, handler http.HandlerFunc)
	HttpHandlerFunc(method, path string, handler HttpHandlerFunc)
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

type ListenOptions

type ListenOptions struct {
	AppPath  string
	Type     string
	SockName string
	BindIP   string
	Port     string
}

type RequestDecoder added in v0.10.0

type RequestDecoder interface {
	ParseToStruct(ctx context.Context, content io.Reader, structPointer any) error
}

type RequestParserBool added in v0.12.0

type RequestParserBool interface {
	FilterNullableBool(r *http.Request, key string) *bool
}

type RequestParserDateTime added in v0.12.0

type RequestParserDateTime interface {
	FilterDateTime(r *http.Request, key string) time.Time
}

type RequestParserFile added in v0.12.0

type RequestParserFile interface {
	FormFile(r *http.Request, key string) (mrtype.File, error)
	FormFileContent(r *http.Request, key string) (mrtype.FileContent, error)
	FormFiles(r *http.Request, key string) ([]mrtype.FileHeader, error)
}

type RequestParserImage added in v0.12.0

type RequestParserImage interface {
	FormImage(r *http.Request, key string) (mrtype.Image, error)
	FormImageContent(r *http.Request, key string) (mrtype.ImageContent, error)
	FormImages(r *http.Request, key string) ([]mrtype.ImageHeader, error)
}

type RequestParserInt64 added in v0.12.0

type RequestParserInt64 interface {
	PathParamInt64(r *http.Request, name string) int64
	FilterInt64(r *http.Request, key string) int64
	FilterRangeInt64(r *http.Request, key string) mrtype.RangeInt64
	FilterInt64List(r *http.Request, key string) []int64
}

type RequestParserItemStatus added in v0.10.0

type RequestParserItemStatus interface {
	FilterStatusList(r *http.Request, key string) []mrenum.ItemStatus
}

type RequestParserKeyInt32 added in v0.10.0

type RequestParserKeyInt32 interface {
	PathKeyInt32(r *http.Request, name string) mrtype.KeyInt32
	FilterKeyInt32(r *http.Request, key string) mrtype.KeyInt32
	FilterKeyInt32List(r *http.Request, key string) []mrtype.KeyInt32
}

type RequestParserListPager added in v0.14.0

type RequestParserListPager interface {
	PageParams(r *http.Request) mrtype.PageParams
}

type RequestParserListSorter added in v0.14.0

type RequestParserListSorter interface {
	SortParams(r *http.Request, sorter mrview.ListSorter) mrtype.SortParams
}

type RequestParserParamFunc added in v0.12.0

type RequestParserParamFunc func(r *http.Request, key string) string

type RequestParserString added in v0.12.0

type RequestParserString interface {
	PathParamString(r *http.Request, name string) string
	// RawParamString - returns nil if the param not found
	RawParamString(r *http.Request, key string) *string
	FilterString(r *http.Request, key string) string
}

type RequestParserUUID added in v0.10.0

type RequestParserUUID interface {
	PathParamUUID(r *http.Request, name string) uuid.UUID
	FilterUUID(r *http.Request, key string) uuid.UUID
}

type RequestParserValidate added in v0.10.0

type RequestParserValidate interface {
	Validate(r *http.Request, structPointer any) error
	ValidateContent(ctx context.Context, content []byte, structPointer any) error
}

type ResponseEncoder added in v0.10.0

type ResponseEncoder interface {
	ContentType() string
	ContentTypeProblem() string
	Marshal(structure any) ([]byte, error)
}

type ResponseSender added in v0.10.0

type ResponseSender interface {
	Send(w http.ResponseWriter, status int, structure any) error
	SendBytes(w http.ResponseWriter, status int, body []byte) error
	SendNoContent(w http.ResponseWriter) error
}

type ServerAdapter added in v0.5.1

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

func NewServerAdapter added in v0.13.0

func NewServerAdapter(ctx context.Context, opts ServerOptions) *ServerAdapter

func (*ServerAdapter) PrepareToStart added in v0.13.0

func (s *ServerAdapter) PrepareToStart(ctx context.Context) (execute func() error, interrupt func(error))

func (*ServerAdapter) Shutdown added in v0.13.0

func (s *ServerAdapter) Shutdown(ctx context.Context) error

func (*ServerAdapter) Start added in v0.5.1

func (s *ServerAdapter) Start(ctx context.Context) error

Start - exec server Serve()

type ServerOptions

type ServerOptions struct {
	Caption         string
	Handler         http.Handler
	ReadTimeout     time.Duration
	WriteTimeout    time.Duration
	ShutdownTimeout time.Duration
	Listen          ListenOptions
}

type StatResponseWriter added in v0.13.0

type StatResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewStatResponseWriter added in v0.13.0

func NewStatResponseWriter(ctx context.Context, w http.ResponseWriter) *StatResponseWriter

func (*StatResponseWriter) Write added in v0.13.0

func (w *StatResponseWriter) Write(buf []byte) (int, error)

func (*StatResponseWriter) WriteHeader added in v0.13.0

func (w *StatResponseWriter) WriteHeader(statusCode int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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