gohttplib

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 8 Imported by: 4

README

gohttplib

Go library with a lot of helpers

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessMiddlewareFactory

func AccessMiddlewareFactory(secret string) func(http.Handler) http.Handler

func BoolParameterFromURLInRequest

func BoolParameterFromURLInRequest(r *http.Request, name string) *bool

func FloatParameterFromURLInRequest

func FloatParameterFromURLInRequest(r *http.Request, name string) *float64

func GetBody

func GetBody(req *http.Request) (map[string]interface{}, error)

func GetParameterFromURLInRequest

func GetParameterFromURLInRequest(r *http.Request, key string) *string

func Int64ParameterFromURLInRequest

func Int64ParameterFromURLInRequest(r *http.Request, name string) *int64

func IntParameterFromURLInRequest

func IntParameterFromURLInRequest(r *http.Request, name string) *int

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

func RecoverMiddleware

func RecoverMiddleware(next http.Handler) http.Handler

func SetInContext

func SetInContext(value interface{}, key interface{}, req *http.Request) *http.Request

func WriteErr

func WriteErr(w http.ResponseWriter, err error)

func WriteJson

func WriteJson(w http.ResponseWriter, value interface{}, code int)

func WriteJsonOrError

func WriteJsonOrError(w http.ResponseWriter, value interface{}, code int, err error)

Types

type DefaultRouter

type DefaultRouter struct {
	DefaultRouter *httprouter.Router
}

func NewDefaultRouter

func NewDefaultRouter() *DefaultRouter

func (*DefaultRouter) Delete

func (self *DefaultRouter) Delete(path string, handler http.Handler)

func (*DefaultRouter) Get

func (self *DefaultRouter) Get(path string, handler http.Handler)

func (*DefaultRouter) Patch added in v0.0.3

func (self *DefaultRouter) Patch(path string, handler http.Handler)

func (*DefaultRouter) Post

func (self *DefaultRouter) Post(path string, handler http.Handler)

func (*DefaultRouter) Put

func (self *DefaultRouter) Put(path string, handler http.Handler)

func (*DefaultRouter) ServeHTTP

func (self *DefaultRouter) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Error

type Error struct {
	Key         string   `json:"key, omitempty"`
	Description string   `json:"description, omitempty"`
	Code        string   `json:"code"`
	Args        []string `json:"args, omitempty"`
}

func NewError

func NewError(key string, description string, code string, args []string) Error

func (Error) AsServerError

func (err Error) AsServerError(code int) error

func (Error) Error

func (err Error) Error() string

func (Error) WriteWithCode

func (err Error) WriteWithCode(code int, w http.ResponseWriter)

type Errors

type Errors struct {
	Errors []Error `json:"errors"`
}

func (Errors) Error

func (errs Errors) Error() string

type IDContainer

type IDContainer struct {
	ID string `json:"id"`
}

func NewIDContainer

func NewIDContainer(id string) *IDContainer

type Middleware

type Middleware func(http.Handler) http.Handler

type Parameters

type Parameters = map[string]interface{}

type Router

type Router interface {
	Get(path string, handler http.Handler)
	Post(path string, handler http.Handler)
	Put(path string, handler http.Handler)
	Patch(path string, handler http.Handler)
	Delete(path string, handler http.Handler)
	ServeHTTP(w http.ResponseWriter, req *http.Request)
}

type ServerError

type ServerError struct {
	StatusCode int
	Errors     Errors
}

func DefaultHTTP403

func DefaultHTTP403() *ServerError

func HTTP400

func HTTP400(description string) *ServerError

func HTTP400Empty

func HTTP400Empty() *ServerError

func HTTP401

func HTTP401() *ServerError

func HTTP403

func HTTP403(code string) *ServerError

func HTTP404

func HTTP404(id string) *ServerError

func HTTP500

func HTTP500(err interface{}) *ServerError

func NewServerError

func NewServerError(statusCode int, code string, description string, key string, args []string) *ServerError

func SafeConvertToServerError

func SafeConvertToServerError(err error) *ServerError

func (ServerError) Error

func (err ServerError) Error() string

func (ServerError) Write

func (err ServerError) Write(w http.ResponseWriter)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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