httpoc

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 27 Imported by: 0

README

HTTPoC

Golang HTTP framework for Proof of Concept development projects

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = &Failure{Code: "unauthorized", Status: http.StatusUnauthorized}
	ErrServerError  = &Failure{Code: "server_error", Status: http.StatusInternalServerError}
	ErrBadRequest   = &Failure{Code: "invalid_request", Status: http.StatusBadRequest}
	ErrNotFound     = &Failure{Code: "not_found", Status: http.StatusNotFound}
)
View Source
var DefaultEngine = new(Engine)

Functions

func DecodeForm

func DecodeForm(r *http.Request, dst interface{}) error

func DecodeQuery

func DecodeQuery(r *http.Request, dst interface{}) error

func Dependency

func Dependency(runners ...runnable.Runnable)

func Dependent

func Dependent(runners ...runnable.Runnable)

func Handle

func Handle(pattern string, handler http.Handler)

func HandleFunc

func HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func Run

func Run(conf interface{})

func WriteFailure

func WriteFailure(w http.ResponseWriter, r *http.Request, err error)

func WriteJSON

func WriteJSON(w http.ResponseWriter, resp interface{})

func WriteResult

func WriteResult(w http.ResponseWriter, r *http.Request, result *Result)

Types

type Engine

type Engine struct {
	http.ServeMux
	*http.Server
	// contains filtered or unexported fields
}

func (*Engine) Dependency

func (e *Engine) Dependency(runners ...runnable.Runnable)

func (*Engine) Dependent

func (e *Engine) Dependent(runners ...runnable.Runnable)

func (*Engine) Handle

func (e *Engine) Handle(pattern string, handler http.Handler)

func (*Engine) HandleFunc

func (e *Engine) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

func (*Engine) Run

func (e *Engine) Run(conf interface{})

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Failure

type Failure struct {
	Code        string `json:"error,omitempty" schema:"error,omitempty"`
	Status      int    `json:"status" schema:"status"`
	Description string `json:"error_description,omitempty" schema:"error_description,omitempty"`
}

func (*Failure) Error

func (f *Failure) Error() string

func (*Failure) From

func (f *Failure) From(err error) *Failure

func (*Failure) MarshalZerologObject

func (f *Failure) MarshalZerologObject(e *zerolog.Event)

type Result

type Result struct {
	Data interface{}
	Err  error
}

func Wrap

func Wrap(data interface{}, err error) *Result

Jump to

Keyboard shortcuts

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