Documentation
¶
Index ¶
- Constants
- Variables
- func AddContext(key string, value interface{})
- func AddLogOutput(w interface{}, key, value string) error
- func AddLoggingMiddleware(next http.HandlerFunc) http.HandlerFunc
- func AddMiddleware(mw Middleware) error
- func ENUM(values ...string) []string
- func ExecuteHandler(handler Handler, method string, expectedStatus int, requestBody []byte, ...)
- func ExecuteHandlerWithGzipRequestAndResponse(handler Handler, method string, expectedStatus int, requestBody []byte, ...)
- func ExecuteHandlerWithGzipResponse(handler Handler, method string, expectedStatus int, requestBody []byte, ...)
- func GetAsBool(key string, r *http.Request) *bool
- func GetAsBoolFromContext(key string, ctx context.Context) *bool
- func GetAsFloat32(key string, r *http.Request) *float32
- func GetAsFloat32FromContext(key string, ctx context.Context) *float32
- func GetAsFloat64(key string, r *http.Request) *float64
- func GetAsFloat64FromContext(key string, ctx context.Context) *float64
- func GetAsInt(key string, r *http.Request) *int
- func GetAsInt32(key string, r *http.Request) *int32
- func GetAsInt32FromContext(key string, ctx context.Context) *int32
- func GetAsInt64(key string, r *http.Request) *int64
- func GetAsInt64FromContext(key string, ctx context.Context) *int64
- func GetAsIntFromContext(key string, ctx context.Context) *int
- func GetAsString(key string, r *http.Request) *string
- func GetAsStringFromContext(key string, ctx context.Context) *string
- func GetAsTime(key string, r *http.Request) *time.Time
- func GetAsTimeFromContext(key string, ctx context.Context) *time.Time
- func GetParamsMiddleware(optionalGet R, requiredGet R) func(next http.HandlerFunc) http.HandlerFunc
- func GzipDecodeRequestBody(r *http.Request, model interface{}) error
- func GzipDecodeResponseBody(res *http.Response) ([]byte, error)
- func GzipEncodeRequestBody(body []byte) (io.ReadCloser, error)
- func Handle(pattern string, handler Handler)
- func ParseBool(value string, key string, validatedMap R, errors *[]error)
- func ParseDate(value string, key string, format string, validatedMap R, errors *[]error)
- func ParseEnum(value string, enum []string, key string, validatedMap R, errors *[]error)
- func ParseFloat(value string, key string, bits int, validatedMap R, errors *[]error)
- func ParseInt(value string, key string, bits int, validatedMap R, errors *[]error)
- func ParseModelMiddleware(postModel interface{}, getModel interface{}, deleteModel interface{}) func(next http.HandlerFunc) http.HandlerFunc
- func ParseString(value string, key string, validatedMap R, errors *[]error)
- func ParsedModel(r *http.Request) interface{}
- func PreProcessMiddleware(preProcess func(ctx context.Context) error) func(next http.HandlerFunc) http.HandlerFunc
- func ReaderHelper(header http.Header, body io.ReadCloser) (io.Reader, error)
- func Render(w http.ResponseWriter, r *http.Request, model interface{})
- func RenderError(w http.ResponseWriter, r *http.Request, err error)
- func RenderErrorWithStatusCode(w http.ResponseWriter, r *http.Request, statusCode int, err error)
- func RenderMessage(w http.ResponseWriter, r *http.Request, msg string)
- func RenderMessageWithStatusCode(w http.ResponseWriter, r *http.Request, statusCode int, msg string)
- func RenderWithStatusCode(w http.ResponseWriter, r *http.Request, statusCode int, model interface{})
- func SelectMethod(chain Middleware, handler Handler) http.HandlerFunc
- func ServeSinglePageApp(path string, mainHTMLFile string)
- func SetConfig(_config Config)
- func SetCorsMiddleware(CORSString *string) func(next http.HandlerFunc) http.HandlerFunc
- func SetJSONResponseMiddleware(next http.HandlerFunc) http.HandlerFunc
- func SinglePageAppHandler(path string, mainHTMLFile string) http.HandlerFunc
- func ValidateParams(requirement R, actual map[string]string, destination R, required bool) error
- type Config
- type ContextMap
- type Handler
- type LoggingResponseWriter
- type Middleware
- type R
Constants ¶
View Source
const ( CtxKeyPostModel string = "uhttp.postModel" CtxKeyGetParams string = "uhttp.getParams" )
Variables ¶
View Source
var Logger ulog.ULogger = ulog.NewUlog()
Functions ¶
func AddContext ¶
func AddContext(key string, value interface{})
func AddLogOutput ¶ added in v1.0.41
func AddLoggingMiddleware ¶ added in v1.0.41
func AddLoggingMiddleware(next http.HandlerFunc) http.HandlerFunc
Logging log time, method and path of an HTTP-Request
func AddMiddleware ¶
func AddMiddleware(mw Middleware) error
func ExecuteHandler ¶ added in v1.0.41
func ExecuteHandlerWithGzipRequestAndResponse ¶ added in v1.0.42
func ExecuteHandlerWithGzipResponse ¶ added in v1.0.42
func GetAsBoolFromContext ¶ added in v1.0.41
func GetAsFloat32FromContext ¶ added in v1.0.41
func GetAsFloat64FromContext ¶ added in v1.0.41
func GetAsInt32FromContext ¶ added in v1.0.41
func GetAsInt64FromContext ¶ added in v1.0.41
func GetAsIntFromContext ¶ added in v1.0.41
func GetAsStringFromContext ¶ added in v1.0.41
func GetAsTimeFromContext ¶ added in v1.0.41
func GetParamsMiddleware ¶ added in v1.0.41
func GetParamsMiddleware(optionalGet R, requiredGet R) func(next http.HandlerFunc) http.HandlerFunc
func GzipDecodeRequestBody ¶ added in v1.0.42
func GzipDecodeResponseBody ¶ added in v1.0.42
func GzipEncodeRequestBody ¶ added in v1.0.42
func GzipEncodeRequestBody(body []byte) (io.ReadCloser, error)
func ParseFloat ¶ added in v1.0.41
func ParseModelMiddleware ¶ added in v1.0.41
func ParseModelMiddleware(postModel interface{}, getModel interface{}, deleteModel interface{}) func(next http.HandlerFunc) http.HandlerFunc
ParseModel parses and adds a model from a requestbody if wanted
func ParseString ¶ added in v1.0.41
func ParsedModel ¶
func PreProcessMiddleware ¶ added in v1.0.41
func PreProcessMiddleware(preProcess func(ctx context.Context) error) func(next http.HandlerFunc) http.HandlerFunc
func ReaderHelper ¶ added in v1.0.39
inspired by https://medium.com/axiomzenteam/put-your-http-requests-on-a-diet-3e1e52333014
func RenderError ¶
func RenderError(w http.ResponseWriter, r *http.Request, err error)
func RenderMessage ¶
func RenderMessage(w http.ResponseWriter, r *http.Request, msg string)
func RenderWithStatusCode ¶
func RenderWithStatusCode(w http.ResponseWriter, r *http.Request, statusCode int, model interface{})
func SelectMethod ¶
func SelectMethod(chain Middleware, handler Handler) http.HandlerFunc
func ServeSinglePageApp ¶
ServeSinglePageApp
func SetCorsMiddleware ¶ added in v1.0.41
func SetCorsMiddleware(CORSString *string) func(next http.HandlerFunc) http.HandlerFunc
SetCors set response headers
func SetJSONResponseMiddleware ¶ added in v1.0.41
func SetJSONResponseMiddleware(next http.HandlerFunc) http.HandlerFunc
SetJSONResponse set response headers
func SinglePageAppHandler ¶ added in v1.0.42
func SinglePageAppHandler(path string, mainHTMLFile string) http.HandlerFunc
Exposed handler for testing
Types ¶
type Config ¶
type ContextMap ¶
type ContextMap map[string]interface{}
func RequestContext ¶
func RequestContext() ContextMap
type Handler ¶
type Handler struct { Pattern string PostHandler http.HandlerFunc PostModel interface{} GetHandler http.HandlerFunc GetModel interface{} DeleteHandler http.HandlerFunc DeleteModel interface{} RequiredGet R OptionalGet R AddMiddlewares []Middleware AddMiddleware *Middleware PreProcess func(ctx context.Context) error Timeout *time.Duration TimeoutMessage *string }
Handler configured
func (Handler) HandlerFunc ¶
func (h Handler) HandlerFunc() http.HandlerFunc
func (Handler) WsReady ¶ added in v1.0.32
func (h Handler) WsReady() Middleware
type LoggingResponseWriter ¶ added in v1.0.41
type LoggingResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
func (*LoggingResponseWriter) AddLogOutput ¶ added in v1.0.41
func (lrw *LoggingResponseWriter) AddLogOutput(key, value string)
func (*LoggingResponseWriter) WriteHeader ¶ added in v1.0.41
func (lrw *LoggingResponseWriter) WriteHeader(code int)
type Middleware ¶
type Middleware func(next http.HandlerFunc) http.HandlerFunc
func AdditionalMiddlewares ¶
func AdditionalMiddlewares() []Middleware
func Chain ¶
func Chain(mw ...Middleware) Middleware
Chain chain multiple middlewares copied from: https://hackernoon.com/simple-http-middleware-with-go-79a4ad62889b
func WithContextMiddleware ¶ added in v1.0.41
func WithContextMiddleware(key string, value interface{}) Middleware
WithContext attaches any object to the context
Source Files
¶
- AdditionalMiddlewares.go
- ChainMiddlewares.go
- Config.go
- ContextKeys.go
- HandlerModel.go
- HelpersGzip.go
- HelpersRendering.go
- Logger.go
- MiddlewareAddLogging.go
- MiddlewareGetParams.go
- MiddlewareModel.go
- MiddlewareParseModel.go
- MiddlewarePreProcess.go
- MiddlewareSetCors.go
- MiddlewareSetJSONResponse.go
- MiddlewareWithContext.go
- ParamsHelpers.go
- ParamsParse.go
- ParamsTypes.go
- ParamsValidate.go
- RequestContext.go
- RequestTrace.go
- SelectMethod.go
- SinglePageAppHandler.go
- TestingHelpers.go
- UHttp.go
Click to show internal directories.
Click to hide internal directories.