mrserver

package
v0.18.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	VarRestOfURL = "{{restOfUrl}}" // VarRestOfURL - comment const
)

Variables

This section is empty.

Functions

func MiddlewareGeneral added in v0.13.0

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

MiddlewareGeneral - comment func.

func MiddlewareHandlerAdapter added in v0.16.0

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

MiddlewareHandlerAdapter - comment func.

func MiddlewareHandlerCheckAccess added in v0.16.0

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

MiddlewareHandlerCheckAccess - comment func.

func MiddlewareHandlerIdempotency added in v0.16.0

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

MiddlewareHandlerIdempotency - comment func.

func MiddlewareRecoverHandler added in v0.17.0

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

MiddlewareRecoverHandler - comment func.

func PrepareAppToStart added in v0.13.0

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

PrepareAppToStart - comment func.

Types

type CacheableResponseWriter added in v0.14.0

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

CacheableResponseWriter - comment struct.

func NewCacheableResponseWriter added in v0.14.0

func NewCacheableResponseWriter(w http.ResponseWriter) *CacheableResponseWriter

NewCacheableResponseWriter - создаёт объект CacheableResponseWriter.

func (*CacheableResponseWriter) Body added in v0.14.0

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

Body - comment method.

func (*CacheableResponseWriter) StatusCode added in v0.14.0

func (w *CacheableResponseWriter) StatusCode() int

StatusCode - comment method.

func (*CacheableResponseWriter) Write added in v0.14.0

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

Write - comment method.

func (*CacheableResponseWriter) WriteHeader added in v0.14.0

func (w *CacheableResponseWriter) WriteHeader(statusCode int)

WriteHeader - comment method.

type ErrorResponseSender added in v0.10.0

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

ErrorResponseSender - отправляет ответ со списком ошибок полученных в результате обработки запроса.

type ErrorStatusGetter added in v0.18.0

type ErrorStatusGetter interface {
	ErrorStatus(err error) int
}

ErrorStatusGetter - возвращает http статус на основе указанной ошибки.

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
}

FileResponseSender - отправляет ответ с данными в виде файла сформированные сервером.

type HttpController added in v0.10.0

type HttpController interface {
	Handlers() []HttpHandler
}

HttpController - http контроллер со списком его обработчиков.

type HttpErrorStatusGetter added in v0.18.0

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

HttpErrorStatusGetter - only for: 401, 403, 404, 418, 5XX.

func NewHttpErrorStatusGetter added in v0.18.0

func NewHttpErrorStatusGetter(unexpectedStatus int) *HttpErrorStatusGetter

NewHttpErrorStatusGetter - создаёт объект HttpErrorStatusGetter.

func (*HttpErrorStatusGetter) ErrorStatus added in v0.18.0

func (g *HttpErrorStatusGetter) ErrorStatus(err error) int

ErrorStatus - comment method.

type HttpHandler added in v0.10.0

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

HttpHandler - http обработчик, к которому привязаны метод, URL и разрешение контролирующее запуск этого обработчика.

type HttpHandlerFunc added in v0.10.0

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

HttpHandlerFunc - изменённый дизайн стандартного HTTP обработчика с возможностью возврата ошибки вместо её обработки в самом обработчике.

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)
}

HttpRouter - роутинг запросов с их регистрацией и запуском.

type ListenOptions

type ListenOptions struct {
	BindIP string
	Port   string
}

ListenOptions - опции для создания Listen.

type RequestDecoder added in v0.10.0

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

RequestDecoder - преобразователь данных в указанную go структуру.

type RequestParserBool added in v0.12.0

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

RequestParserBool - парсер данных запроса для преобразования их в *bool.

type RequestParserDateTime added in v0.12.0

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

RequestParserDateTime - парсер данных запроса для преобразования их в 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)
}

RequestParserFile - парсер данных запроса для преобразования их в файловую структуру.

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)
}

RequestParserImage - парсер данных запроса для преобразования их в файловую структуру изображения.

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
}

RequestParserInt64 - парсер данных запроса для преобразования их в int64.

type RequestParserItemStatus added in v0.10.0

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

RequestParserItemStatus - парсер данных запроса для преобразования их в []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
}

RequestParserKeyInt32 - парсер данных запроса для преобразования их в mrtype.KeyInt32.

type RequestParserListPager added in v0.14.0

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

RequestParserListPager - парсер данных запроса для преобразования их в mrtype.PageParams.

type RequestParserListSorter added in v0.14.0

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

RequestParserListSorter - парсер данных запроса для преобразования их в mrtype.SortParams.

type RequestParserParamFunc added in v0.12.0

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

RequestParserParamFunc - функция для парсинга URL для извлечения из него параметров.

type RequestParserString added in v0.12.0

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

RequestParserString - парсер данных запроса для преобразования их в 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
}

RequestParserUUID - парсер данных запроса для преобразования их в 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
}

RequestParserValidate - парсер данных запроса для преобразования их в go структуру.

type ResponseEncoder added in v0.10.0

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

ResponseEncoder - формирует ответ сервера из go структуры в необходимом формате.

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
}

ResponseSender - отправляет ответ с данными сформированные сервером.

type ServerAdapter added in v0.5.1

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

ServerAdapter - comment struct.

func NewServerAdapter added in v0.13.0

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

NewServerAdapter - создаёт объект ServerAdapter.

func (*ServerAdapter) PrepareToStart added in v0.13.0

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

PrepareToStart - comment method.

func (*ServerAdapter) Shutdown added in v0.13.0

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

Shutdown - comment method.

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
}

ServerOptions - опции для создания Server.

type StatRequest added in v0.17.0

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

StatRequest - comment struct.

func NewStatRequest added in v0.17.0

func NewStatRequest(r *http.Request) *StatRequest

NewStatRequest - создаёт объект StatRequest. WARNING: the Body of the original http.Request will be replaced.

func (*StatRequest) Bytes added in v0.17.0

func (r *StatRequest) Bytes() int

Bytes - comment method.

func (*StatRequest) Request added in v0.17.0

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

Request - comment method.

type StatResponseWriter added in v0.13.0

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

StatResponseWriter - comment struct.

func NewStatResponseWriter added in v0.13.0

func NewStatResponseWriter(w http.ResponseWriter, onWrite func(buf []byte)) *StatResponseWriter

NewStatResponseWriter - создаёт объект StatResponseWriter.

func (*StatResponseWriter) Bytes added in v0.17.0

func (w *StatResponseWriter) Bytes() int

Bytes - comment method.

func (*StatResponseWriter) StatusCode added in v0.17.0

func (w *StatResponseWriter) StatusCode() int

StatusCode - comment method.

func (*StatResponseWriter) Write added in v0.13.0

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

Write - comment method.

func (*StatResponseWriter) WriteHeader added in v0.13.0

func (w *StatResponseWriter) WriteHeader(statusCode int)

WriteHeader - comment method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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