transhttp

package
v0.0.0-...-96965a9 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 10 * time.Second
)

Variables

View Source
var ErrorNotFound = errors.New("not found")
View Source
var ErrorTooManyRequest = errors.New("too many request")

Functions

func GetStatusCode

func GetStatusCode(err error) int

GetStatusCode --

func NewRouter

func NewRouter(routes []Routes, middlewares [][]negroni.Handler) *mux.Router

NewRouter -- load all routers

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, url string)

Redirect -- redirect

func RespondError

func RespondError(w http.ResponseWriter, httpStatusCode int, message string)

RespondError -- makes the error response with payload as json format

func RespondFile

func RespondFile(w http.ResponseWriter, r *http.Request, fileName string)

RespondFile --

func RespondJSON

func RespondJSON(w http.ResponseWriter, httpStatusCode int, payload interface{})

RespondJSON -- makes the response with payload as json format

func RespondJSONError

func RespondJSONError(w http.ResponseWriter, payload interface{})

RespondJSONError --

func RespondMessage

func RespondMessage(w http.ResponseWriter, httpStatusCode int, message string)

RespondMessage -- makes the message response with payload as json format

func RespondMessageWithContentType

func RespondMessageWithContentType(w http.ResponseWriter, httpStatusCode int, message string, contentType string)

RespondMessageWithContentType -- makes the message response with payload as json format

Types

type HealthCheckHandler

type HealthCheckHandler struct {
}

func NewHealthCheckHandler

func NewHealthCheckHandler() *HealthCheckHandler

NewHealthCheckHandler --

func (*HealthCheckHandler) ServeHTTP

func (h *HealthCheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP --

type Route

type Route struct {
	Name        string
	Method      string
	BasePath    string
	Pattern     string
	Handler     http.Handler
	Middlewares []negroni.Handler
	Timeout     time.Duration
}

Route -- Defines a single route, e.g. a human readable name, HTTP method, pattern the function that will execute when the route is called.

type Routes

type Routes []Route

Routes -- Defines the type Routes which is just an array (slice) of Route structs.

type WebServer

type WebServer interface {
	InitRoutes() Routes
	InitMiddlewares() []negroni.Handler
	OnClose()
}

WebServer --

Jump to

Keyboard shortcuts

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