Documentation ¶
Index ¶
- Constants
- Variables
- func GetStatusCode(err error) int
- func NewRouter(routes []Routes, middlewares [][]negroni.Handler) *mux.Router
- func Redirect(w http.ResponseWriter, r *http.Request, url string)
- func RespondError(w http.ResponseWriter, httpStatusCode int, message string)
- func RespondFile(w http.ResponseWriter, r *http.Request, fileName string)
- func RespondJSON(w http.ResponseWriter, httpStatusCode int, payload interface{})
- func RespondJSONError(w http.ResponseWriter, payload interface{})
- func RespondMessage(w http.ResponseWriter, httpStatusCode int, message string)
- func RespondMessageWithContentType(w http.ResponseWriter, httpStatusCode int, message string, contentType string)
- type HealthCheckHandler
- type Route
- type Routes
- type WebServer
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 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.
Click to show internal directories.
Click to hide internal directories.