mrserver

package
v0.17.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ListenTypeSock = "sock"
	ListenTypePort = "port"
)
View Source
const (
	VarRestOfURL = "{restOfUrl}"
)

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 MiddlewareGeneral added in v0.13.0

func MiddlewareGeneral(
	tr *mrlang.Translator,
	statFunc func(l mrlog.Logger, start time.Time, sr *StatRequest, sw *StatResponseWriter),
) func(next http.Handler) http.Handler

func MiddlewareHandlerAdapter added in v0.16.0

func MiddlewareHandlerAdapter(s ErrorResponseSender) func(next HttpHandlerFunc) http.HandlerFunc

func MiddlewareHandlerCheckAccess added in v0.16.0

func MiddlewareHandlerCheckAccess(handlerName string, access mrperms.AccessControl, privilege, permission string) func(next HttpHandlerFunc) HttpHandlerFunc

func MiddlewareHandlerIdempotency added in v0.16.0

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

func MiddlewareRecoverHandler added in v0.17.0

func MiddlewareRecoverHandler(isDebug bool, fatalFunc http.HandlerFunc) func(next http.Handler) http.Handler

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 HttpHandlerFunc added in v0.10.0

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

type HttpRouter added in v0.10.0

type HttpRouter interface {
	RegisterMiddleware(handlers ...func(next http.Handler) http.Handler)
	Register(controllers ...HttpController)
	HandlerFunc(method, path string, handler http.HandlerFunc)
	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 StatRequest added in v0.17.0

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

func NewStatRequest added in v0.17.0

func NewStatRequest(r *http.Request) *StatRequest

NewStatRequest - WARNING: the Body of the original http.Request will be replaced

func (*StatRequest) Bytes added in v0.17.0

func (r *StatRequest) Bytes() int

func (*StatRequest) Request added in v0.17.0

func (r *StatRequest) Request() *http.Request

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(w http.ResponseWriter, onWrite func(buf []byte)) *StatResponseWriter

func (*StatResponseWriter) Bytes added in v0.17.0

func (w *StatResponseWriter) Bytes() int

func (*StatResponseWriter) StatusCode added in v0.17.0

func (w *StatResponseWriter) StatusCode() int

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