Documentation ¶
Index ¶
- func DefaultRestHandlerWrapperFunc(entry RestEntry) http.HandlerFunc
- func GetBoolParamValue(r *http.Request, paramName string, defaultValue bool) (res bool)
- func GetEnumParamArray(r *http.Request, paramName string, enum interface{}) (res []int)
- func GetEnumParamValue(r *http.Request, paramName string, enum interface{}, defaultValue int) (res int)
- func GetFloatParamValue(r *http.Request, paramName string, defaultValue float64) (res float64)
- func GetInt64ParamValue(r *http.Request, paramName string, defaultValue int64) (res int64)
- func GetIntParamArray(r *http.Request, paramName string) (res []int)
- func GetIntParamValue(r *http.Request, paramName string, defaultValue int) (res int)
- func GetIntParamValueFromPath(r *http.Request, paramName string, defaultValue int) int
- func GetStringParamArray(r *http.Request, paramName string) (res []string)
- func GetStringParamValue(r *http.Request, paramName string, defaultValue string) (res string)
- func GetStringParamValueFromPath(r *http.Request, paramName string, defaultValue string) (res string)
- func GetUInt64ParamArray(r *http.Request, paramName string) (res []uint64)
- func GetUint64ParamValue(r *http.Request, paramName string, defaultValue uint64) (res uint64)
- func ResolveRemoteIpFromHttpRequest(r *http.Request) (ip string)
- type ActionResponse
- type BaseRestResponse
- type EntitiesResponse
- type EntityResponse
- type IRestEndpoint
- type IRestResponse
- type IStaticEndpoint
- type RequestWithToken
- type RestEndpoint
- type RestEntries
- type RestEntry
- type RestHandler
- type RestHandlerAdaptorFunc
- type StaticEndpoint
- type StaticFilesEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultRestHandlerWrapperFunc ¶
func DefaultRestHandlerWrapperFunc(entry RestEntry) http.HandlerFunc
func GetBoolParamValue ¶
GetBoolParamValue extracts parameter value from query string as bool
func GetEnumParamArray ¶
GetEnumParamArray extracts parameter array values from query string as enums to support multiple values query string e.g. https//some/domain?id=1&id=2&id=3
func GetEnumParamValue ¶
func GetEnumParamValue(r *http.Request, paramName string, enum interface{}, defaultValue int) (res int)
GetEnumParamValue extracts parameter value from query string as enum Enum value can be passed as it's int or string value
func GetFloatParamValue ¶
GetFloatParamValue extract parameter value from query string as float64
func GetInt64ParamValue ¶
GetInt64ParamValue extract parameter value from query string as long
func GetIntParamArray ¶
GetIntParamArray extract parameter array values from query string to support multiple values query string e.g. https//some/domain?id=1&id=2&id=3
func GetIntParamValue ¶
GetIntParamValue extract parameter value from query string as int
func GetIntParamValueFromPath ¶
GetIntParamValueFromPath extracts parameter value from path params as int
func GetStringParamArray ¶
GetStringParamArray extracts parameter array values from query string to support multiple values query string e.g. https//some/domain?id=1&id=2&id=3
func GetStringParamValue ¶
GetStringParamValue extract parameter value from query string as string
func GetStringParamValueFromPath ¶
func GetStringParamValueFromPath(r *http.Request, paramName string, defaultValue string) (res string)
GetStringParamValueFromPath extracts parameter value from path params as string
func GetUInt64ParamArray ¶
GetUInt64ParamArray extract parameter array values from query string This supports multiple values query string e.g. https//some/domain?id=1&id=2&id=3
func GetUint64ParamValue ¶
GetUint64ParamValue extract parameter value from query string as unsigned-long
func ResolveRemoteIpFromHttpRequest ¶
ResolveRemoteIpFromHttpRequest extracts remote ip from HTTP header X-Forwarded-For
Types ¶
type ActionResponse ¶
type ActionResponse struct { BaseRestResponse Key string `json:"key,omitempty"` // The entity key (Id) Data string `json:"data,omitempty"` // Additional data }
ActionResponse message is returned for any action on entity with no return data (e.d. delete)
func NewActionResponse ¶
func NewActionResponse(key, data string) (er *ActionResponse)
NewActionResponse factory method
func NewActionResponseError ¶
func NewActionResponseError(err error) (res *ActionResponse)
NewActionResponseError with error
type BaseRestResponse ¶
type BaseRestResponse struct { Code int `json:"code"` // Error code (0 for success) Error string `json:"error,omitempty"` // Error message }
BaseRestResponse is a common structure for all response types
func (*BaseRestResponse) SetError ¶
func (res *BaseRestResponse) SetError(err error)
type EntitiesResponse ¶
type EntitiesResponse struct { BaseRestResponse Page int `json:"page"` // Current page (Bulk) number PageSize int `json:"pageSize"` // Size of page (items in bulk) Pages int `json:"pages"` // Total number of pages Total int `json:"total"` // Total number of items in the query List []Entity `json:"list"` // List of objects in the current result set }
EntitiesResponse message is returned for any action returning multiple entities
func NewEntitiesResponse ¶
func NewEntitiesResponse(entities []Entity, page, pageSize, total int) *EntitiesResponse
NewEntitiesResponse factory method
func NewEntitiesResponseError ¶
func NewEntitiesResponseError(err error) *EntitiesResponse
NewEntitiesResponseError with error
type EntityResponse ¶
type EntityResponse struct { BaseRestResponse Entity Entity `json:"entity"` // The entity }
EntityResponse message is returned for any create/update action on entity
func NewEntityResponse ¶
func NewEntityResponse(entity Entity) (er *EntityResponse)
NewEntityResponse factory method
func NewEntityResponseError ¶
func NewEntityResponseError(err error) (res *EntityResponse)
NewEntityResponseError with error
type IRestEndpoint ¶
type IRestEndpoint interface {
Entries() []RestEntry
}
func NewRestEndpoint ¶
func NewRestEndpoint(entries []RestEntry) IRestEndpoint
type IRestResponse ¶
type IRestResponse interface { GetErrorCode() int GetErrorMessage() string SetError(err error) GetRawContent() []byte SetRawContent(content []byte) GetMimeType() string SetMimeType(mimeType string) GetHeaders() map[string]string SetHeader(key string, value string) }
IRestResponse is an interface that all rest response messages must comply
type IStaticEndpoint ¶
type IStaticEndpoint interface {
Entries() []StaticFilesEntry
}
func NewStaticEndpoint ¶
func NewStaticEndpoint(entries []StaticFilesEntry) IStaticEndpoint
type RequestWithToken ¶
type RequestWithToken struct { *http.Request Token string ResponseWriter http.ResponseWriter }
RequestWithToken includes access to the JWT token
func NewRequestWithToken ¶
func NewRequestWithToken(rw http.ResponseWriter, r *http.Request, token string) *RequestWithToken
NewRequestWithToken is the factory method of RequestWithToken
type RestEndpoint ¶
type RestEndpoint struct {
// contains filtered or unexported fields
}
func (RestEndpoint) Entries ¶
func (r RestEndpoint) Entries() []RestEntry
type RestEntries ¶
type RestEntries []*RestEntry
func (RestEntries) Len ¶
func (a RestEntries) Len() int
func (RestEntries) Less ¶
func (a RestEntries) Less(i, j int) bool
func (RestEntries) Swap ¶
func (a RestEntries) Swap(i, j int)
type RestEntry ¶
type RestEntry struct { Path string // Rest method path Method string // HTTP method verb Handler RestHandler // Handler function (http.HandlerFunc) }
type RestHandler ¶
type RestHandler func(r *RequestWithToken) (IRestResponse, error)
RestHandler function signature
type RestHandlerAdaptorFunc ¶
type RestHandlerAdaptorFunc func(entry RestEntry) http.HandlerFunc
RestHandlerAdaptorFunc function signature
type StaticEndpoint ¶
type StaticEndpoint struct {
// contains filtered or unexported fields
}
func (StaticEndpoint) Entries ¶
func (r StaticEndpoint) Entries() []StaticFilesEntry