Documentation ¶
Index ¶
- Constants
- func CreateToken(username string, config *config.HTTPConfig) (string, error)
- func Index(w http.ResponseWriter, r *http.Request)
- func ReturnAccessControlAllowOrigin(cors map[string]bool, checkURL string) (string, error)
- type BaseHandler
- type GetEvents
- type GetEventsRequest
- type GetEventsResponse
- type PostLogin
- type PostLoginRequest
- type PostLoginResponse
- type PostLoginResponseData
- type PostSignup
- type PostSignupRequest
- type PostSignupResponse
- type PostSignupResponseData
- type PostUser
- type PostUserRequest
- type PostUserResponse
- type PrometheusHandler
- type ReqContext
Constants ¶
const ( CategoryAuth = "Auth" CategoryEvent = "Event" CategoryUser = "User" )
Categories for handlers
Variables ¶
This section is empty.
Functions ¶
func CreateToken ¶ added in v1.1.0
func CreateToken(username string, config *config.HTTPConfig) (string, error)
CreateToken creates a signed JWT for user login
func Index ¶
func Index(w http.ResponseWriter, r *http.Request)
Index main function for the API. Returns ok status
func ReturnAccessControlAllowOrigin ¶ added in v1.1.0
ReturnAccessControlAllowOrigin returns the appropriate Access-Control-Allow-Origin based on a map of acceptable domains TODO: Account for when the origin is not passed in
Types ¶
type BaseHandler ¶
type BaseHandler struct { http.Handler Name string Category string DB *gorm.DB CORS map[string]bool Config *config.HTTPConfig }
BaseHandler This is the base handler all the handlers extend
func NewBaseHandler ¶
func NewBaseHandler(db *gorm.DB, cors map[string]bool) BaseHandler
NewBaseHandler returns a new base handler
func (*BaseHandler) WriteResponse ¶
func (b *BaseHandler) WriteResponse(w http.ResponseWriter, reqCtx *ReqContext)
WriteResponse writes a response back to the user
type GetEvents ¶
type GetEvents struct {
BaseHandler
}
GetEvents object that represents the GET events handler
type GetEventsRequest ¶
type GetEventsRequest struct {
Limit int `json:"limit" yaml:"limit"`
}
GetEventsRequest request for GET events
type GetEventsResponse ¶
type GetEventsResponse struct { Status int `json:"status" yaml:"status"` Data []models.Event `json:"data" yaml:"data"` }
GetEventsResponse the response object for GET events
type PostLogin ¶ added in v1.1.0
type PostLogin struct {
BaseHandler
}
PostLogin post login handler object
type PostLoginRequest ¶ added in v1.1.0
type PostLoginRequest struct { Username string `json:"username" yaml:"username"` Password string `json:"password" yaml:"password"` }
PostLoginRequest login request object
type PostLoginResponse ¶ added in v1.1.0
type PostLoginResponse struct { Status int `json:"status" yaml:"status"` Data PostLoginResponseData `json:"data" yaml:"data"` }
PostLoginResponse returns a response object with status and data
type PostLoginResponseData ¶ added in v1.1.0
type PostLoginResponseData struct { Username string `json:"username" yaml:"username"` Token string `json:"token" yaml:"token"` }
PostLoginResponseData login request response object
type PostSignup ¶ added in v1.1.0
type PostSignup struct {
BaseHandler
}
PostSignup for user signup handler
func (PostSignup) ServeHTTP ¶ added in v1.1.0
func (h PostSignup) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP the handler for POST signup
type PostSignupRequest ¶ added in v1.1.0
type PostSignupRequest struct { Username string `json:"username" yaml:"username"` Password string `json:"password" yaml:"password"` }
PostSignupRequest req object for POST signup
type PostSignupResponse ¶ added in v1.1.0
type PostSignupResponse struct { Status int `json:"status" yaml:"status"` Data PostSignupResponseData `json:"data" yaml:"data"` }
PostSignupResponse response for POST signup
type PostSignupResponseData ¶ added in v1.1.0
type PostSignupResponseData struct { Username string `json:"username" yaml:"username"` Token string `json:"token" yaml:"token"` }
PostSignupResponseData represents the data object in the response for POST signup
type PostUser ¶ added in v1.1.0
type PostUser struct {
BaseHandler
}
PostUser POST user handler for creating a user
type PostUserRequest ¶ added in v1.1.0
type PostUserRequest struct {
Username string `json:"username" yaml:"username"`
}
PostUserRequest request for user
type PostUserResponse ¶ added in v1.1.0
type PostUserResponse struct { Status int `json:"status" yaml:"status"` Data []models.User `json:"data" yaml:"data"` }
PostUserResponse handles the response for POST user with status and data
type PrometheusHandler ¶
type PrometheusHandler struct { Path string Handle http.HandlerFunc Metrics *metrics.Metrics }
PrometheusHandler is an HTTP handle for serving metric data
func NewPrometheusHandler ¶
func NewPrometheusHandler() *PrometheusHandler
NewPrometheusHandler is a factory function creating a new Metrics instance
type ReqContext ¶
type ReqContext struct { ErrorCode string `json:"errorCode"` ErrorDetail string `json:"errorDetail"` HTTPStatusCode int `json:"httpStatus"` // Reply can be any type convertible to valid JSON HTTPReply interface{} }
ReqContext object for the context of a request