Documentation
¶
Index ¶
- Constants
- func CreateHandler(h Handler, l *util.Logger) http.HandlerFunc
- func CreateWSHandler(h WSHandler, l *util.Logger) http.HandlerFunc
- func NewErrorBody(c string, msg string) []byte
- func StartServer(h http.Handler, cfg *HTTPConfig, logger *util.Logger, ...)
- type ContentType
- type ErrorBody
- type HTTPConfig
- type Handler
- type Response
- type WSHandler
Constants ¶
const (
// RequestLogger ключ контекста для логгера.
RequestLogger ctxKey = "logger"
)
Variables ¶
This section is empty.
Functions ¶
func CreateHandler ¶
func CreateHandler(h Handler, l *util.Logger) http.HandlerFunc
CreateHandler создает обертку, которая преобразует переданный обработчик в стандартный http.Handler
func CreateWSHandler ¶
func CreateWSHandler(h WSHandler, l *util.Logger) http.HandlerFunc
CreateWSHandler создает обертку, которая преобразует переданный обработчик в стандартный http.Handler
func NewErrorBody ¶
NewErrorBody создает новое тело ответа, содержащего ошибку
func StartServer ¶
func StartServer(h http.Handler, cfg *HTTPConfig, logger *util.Logger, stopChannel <-chan struct{})
StartServer запускает http сервер с обработчиком h.
Types ¶
type ContentType ¶
type ContentType string
ContentType тип возвращаемого значения
const ( ContentTypeRaw ContentType = "application/octet-stream" ContentTypeJSON ContentType = "application/json" ContentTypeHTML ContentType = "text/html" )
Возможные типы ContentType
type HTTPConfig ¶
HTTPConfig настройки для работы встроенного http сервера.
func NewtHTTPConfig ¶
func NewtHTTPConfig() *HTTPConfig
NewtHTTPConfig создает HTTPConfig с настройками по-умолчанию.
func (*HTTPConfig) GetAddr ¶
func (c *HTTPConfig) GetAddr() string
GetAddr возвращает адрес в виде host:port
type Response ¶
type Response struct { StatusCode int Body []byte ContentType ContentType }
Response представляет ответ обработчика.
func NewBadRequestResponse ¶
NewBadRequestResponse возвращает Response с кодом 400 Bad Request
func NewConflictResponse ¶
NewConflictResponse возвращает Response с кодом 409 Conflict
func NewInternalErrorResponse ¶
NewInternalErrorResponse возвращает Response с кодом 500 Internal Server Error
func NewNotFoundResponse ¶
NewNotFoundResponse возвращает Response с кодом 404 Not Found
func NewOKResponse ¶
func NewOKResponse(body []byte, t ContentType) *Response
NewOKResponse возвращает 200 OK, если body ненулевое и 204 No Content, если body нулевое.