Documentation
¶
Index ¶
- Variables
- func GetOptions(opt url.Values) (skip, limit, page int64)
- func Health(server *Server) http.HandlerFunc
- func RawRoutesList(server *Server) http.HandlerFunc
- func RequestScheme(r *http.Request) string
- func ResponseJsonWithError(w http.ResponseWriter, code int, errorResponse *ErrorResponse) error
- func ResponseWithError(w http.ResponseWriter, code int, msg string) error
- func ResponseWithJSON(w http.ResponseWriter, code int, payload interface{}) error
- func ResponseWithPagination(w http.ResponseWriter, code int, payload interface{}) error
- func ResponseWithPaginationTest(w http.ResponseWriter, code int, options *PaginationOptions) error
- func RoutesList(server *Server) http.HandlerFunc
- func Serve(servers []*Server)
- type Endpoint
- type EndpointOptions
- type ErrorResponse
- type GroupOptions
- type PaginationOptions
- type ResponsePagination
- type Server
- func (server *Server) ApplyMiddlewares(mux http.Handler) http.Handler
- func (server *Server) Endpoint(path string, handler http.HandlerFunc)
- func (server *Server) EndpointIsPublic(r *http.Request) bool
- func (server *Server) GetEndpoint(r *http.Request) (*Endpoint, bool)
- func (server *Server) GetEndpoints() map[string]*Endpoint
- func (server *Server) Group(group string, apiEndpoints []Endpoint)
- func (server *Server) GroupWithOptions(group string, apiEndpoints []Endpoint, groupOptions *GroupOptions)
- func (server *Server) LogRequest(next http.Handler) http.Handler
- func (server *Server) NoRequiresAuthentication(r *http.Request) bool
- func (server *Server) Run()
- func (server *Server) Use(middlewares ...func(next http.Handler, server *Server) http.Handler)
- func (server *Server) ValidateSecret(next http.Handler) http.Handler
- type Settings
Constants ¶
This section is empty.
Variables ¶
var ServerEndpoints = []Endpoint{ {Path: "GET /_health", HandlerServerFunc: Health, Options: EndpointOptions{IsPublic: true, NoRequiresAuthentication: true, IgnorePrefix: true}}, {Path: "GET /_routes", HandlerServerFunc: RoutesList, Options: EndpointOptions{IsPublic: true, NoRequiresAuthentication: true, IgnorePrefix: true}}, {Path: "GET /_routes/raw", HandlerServerFunc: RawRoutesList, Options: EndpointOptions{IsPublic: true, NoRequiresAuthentication: true, IgnorePrefix: true}}, }
ServerEndpoints is the list of endpoints for the server
Functions ¶
func GetOptions ¶ added in v1.3.2
func RawRoutesList ¶ added in v1.3.0
func RawRoutesList(server *Server) http.HandlerFunc
func RequestScheme ¶ added in v1.3.3
func ResponseJsonWithError ¶ added in v1.3.2
func ResponseJsonWithError(w http.ResponseWriter, code int, errorResponse *ErrorResponse) error
func ResponseWithError ¶
func ResponseWithError(w http.ResponseWriter, code int, msg string) error
ResponseWithError return a json response with an error
func ResponseWithJSON ¶
func ResponseWithJSON(w http.ResponseWriter, code int, payload interface{}) error
ResponseWithJSON return a json response
func ResponseWithPagination ¶ added in v1.3.0
func ResponseWithPagination(w http.ResponseWriter, code int, payload interface{}) error
func ResponseWithPaginationTest ¶ added in v1.3.2
func ResponseWithPaginationTest(w http.ResponseWriter, code int, options *PaginationOptions) error
Types ¶
type Endpoint ¶ added in v1.2.0
type Endpoint struct {
Path string
HandlerFunc http.HandlerFunc
Handler http.Handler // Handler is a http.Handler and is used to create a new http.Handler with the server's middlewares and endpoints
HandlerServerFunc func(server *Server) http.HandlerFunc // HandlerServerFunc is a function that returns a http.HandlerFunc and is used to create a new http.HandlerFunc with the server's middlewares and endpoints
Options EndpointOptions
RegexPattern *regexp.Regexp
}
Endpoint is a struct that contains the endpoint's configuration and handlers
type EndpointOptions ¶ added in v1.2.0
EndpointOptions is a struct that contains the endpoint's options
type ErrorResponse ¶ added in v1.3.2
type GroupOptions ¶ added in v1.3.14
type PaginationOptions ¶ added in v1.3.2
type ResponsePagination ¶ added in v1.3.0
type ResponsePagination struct {
TotalPages int64 `json:"total_pages"`
Total int64 `json:"total"`
CurrentPage int64 `json:"current_page"`
From int64 `json:"from"`
To int64 `json:"to"`
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
PerPage int `json:"per_page"`
Path string `json:"path"`
FirstPageURL string `json:"first_page_url"`
NextPageURL string `json:"next_page_url"`
LastPageURL string `json:"last_page_url"`
PrevPageURL string `json:"prev_page_url"`
Data interface{} `json:"data"`
}
func (*ResponsePagination) Set ¶ added in v1.3.2
func (p *ResponsePagination) Set()
type Server ¶
type Server struct {
ServerName string
ServerNumber string
RunningServerMessage string
Secret string
Debug bool
Port string
Middlewares []func(next http.Handler, server *Server) http.Handler
Endpoints [][]Endpoint
EndpointsPaths map[string]*Endpoint
CorsOptions cors.Options
Settings *Settings
}
Server is a struct that contains the server's configuration and endpoints
func (*Server) ApplyMiddlewares ¶ added in v1.2.0
ApplyMiddlewares apply all middlewares to the mux; if the server is in debug mode, the server will be register the LogRequest middleware that will log the request on the console if the server has a secret, the server will be register the ValidateSecret middleware that will check if the request has a secret
func (*Server) Endpoint ¶ added in v1.3.3
func (server *Server) Endpoint(path string, handler http.HandlerFunc)
func (*Server) EndpointIsPublic ¶ added in v1.2.0
EndpointIsPublic evalue if the endpoint is public
func (*Server) GetEndpoint ¶ added in v1.2.0
GetEndpoint evaluate if a path exists in the endpoints and return the endpoint and a bool if exists
func (*Server) GetEndpoints ¶ added in v1.2.0
GetEndpoints return all endpoints
func (*Server) GroupWithOptions ¶ added in v1.3.14
func (server *Server) GroupWithOptions(group string, apiEndpoints []Endpoint, groupOptions *GroupOptions)
func (*Server) LogRequest ¶ added in v1.2.0
LogRequest log the request on the console