handlers

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
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

func ReturnAccessControlAllowOrigin(cors map[string]bool, checkURL string) (string, error)

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

func (GetEvents) ServeHTTP

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

ServeHTTP the handler for GetEvents

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

func (PostLogin) ServeHTTP added in v1.1.0

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

ServeHTTP handler for PostLogin

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

func (PostUser) ServeHTTP added in v1.1.0

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

ServeHTTP main function for handler

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

Jump to

Keyboard shortcuts

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