Documentation ¶
Index ¶
- func APIInvalidHandler(w http.ResponseWriter, _ *http.Request)
- func ClientIP(r *http.Request, realIPHeader string) string
- func DestroySessionsForUserID(dbMap *gorp.DbMap, userID int64) error
- func DisableLog()
- func GojiWebHandlerFunc(h http.HandlerFunc) web.HandlerFunc
- func Logger(RealIPHeader string) func(c *web.C, h http.Handler) http.Handler
- func ReloadTemplatesSig(app *Application)
- func UseLogger(logger slog.Logger)
- func WriteAPIResponse(resp *APIResponse, code int, w http.ResponseWriter)
- type APIResponse
- type Application
- func (application *Application) APIHandler(apiFun func(web.C, *http.Request) *APIResponse) web.HandlerFunc
- func (application *Application) ApplyAPI(c *web.C, h http.Handler) http.Handler
- func (application *Application) ApplyAuth(c *web.C, h http.Handler) http.Handler
- func (application *Application) ApplyCaptcha(c *web.C, h http.Handler) http.Handler
- func (application *Application) ApplyDbMap(c *web.C, h http.Handler) http.Handler
- func (application *Application) ApplySessions(c *web.C, h http.Handler) http.Handler
- func (application *Application) ApplyTemplates(c *web.C, h http.Handler) http.Handler
- func (application *Application) Init(ctx context.Context, wg *sync.WaitGroup, ...)
- func (application *Application) LoadTemplates(templatePath string) error
- func (application *Application) Route(controller interface{}, route string) web.HandlerFunc
- type Controller
- func (controller *Controller) CheckPasswordResetToken(tokenStr string, c web.C) (models.UserToken, *models.PasswordReset, bool)
- func (controller *Controller) GetDbMap(c web.C) *gorp.DbMap
- func (controller *Controller) GetSession(c web.C) *sessions.Session
- func (controller *Controller) GetTemplate(c web.C) *template.Template
- func (controller *Controller) IsCaptchaDone(c web.C) bool
- func (controller *Controller) Parse(t *template.Template, name string, data interface{}) string
- type SQLStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIInvalidHandler ¶
func APIInvalidHandler(w http.ResponseWriter, _ *http.Request)
APIInvalidHandler responds to invalid requests. It matches the signature of http.HanderFunc.
func ClientIP ¶
ClientIP gets the client's real IP address using the X-Real-IP header, or if that is empty, http.Request.RemoteAddr. See the sample nginx.conf for using the real_ip module to correctly set the X-Real-IP header.
func DestroySessionsForUserID ¶
DestroySessionsForUserID deletes all sessions from the db for userId
It should be noted that this does not prevent the user's current session from being saved again, which can be achieved by setting MaxAge to -1
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
func GojiWebHandlerFunc ¶
func GojiWebHandlerFunc(h http.HandlerFunc) web.HandlerFunc
GojiWebHandlerFunc is an adaptor that allows an http.HanderFunc where a web.HandlerFunc is required.
func Logger ¶
Logger is a middleware that logs the start and end of each request, along with some useful data about what was requested, what the response status was, and how long it took to return. This should be used after the RequestID middleware.
func ReloadTemplatesSig ¶
func ReloadTemplatesSig(app *Application)
func UseLogger ¶
UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using slog.
func WriteAPIResponse ¶
func WriteAPIResponse(resp *APIResponse, code int, w http.ResponseWriter)
WriteAPIResponse marshals the given poolapi.Response into the http.ResponseWriter and sets HTTP status code.
Types ¶
type APIResponse ¶
type APIResponse struct { Status string `json:"status"` Code codes.Code `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
APIResponse is the response struct used by the server to marshal to a JSON object. Data should be another struct with JSON tags.
func NewAPIResponse ¶
func NewAPIResponse(status string, code codes.Code, message string, data interface{}) *APIResponse
NewAPIResponse is a constructor for APIResponse.
type Application ¶
type Application struct { APISecret string Template *template.Template TemplatesPath string Store *SQLStore DbMap *gorp.DbMap }
func (*Application) APIHandler ¶
func (application *Application) APIHandler(apiFun func(web.C, *http.Request) *APIResponse) web.HandlerFunc
APIHandler executes an API processing function that provides an *APIResponse required by WriteAPIResponse. It returns an web.HandlerFunc so it can be used with a goji router.
func (*Application) ApplyCaptcha ¶
func (*Application) ApplyDbMap ¶
func (*Application) ApplySessions ¶
ApplySessions makes sure controllers can have access to session
func (*Application) ApplyTemplates ¶
ApplyTemplates makes sure templates are stored in the context
func (*Application) LoadTemplates ¶
func (application *Application) LoadTemplates(templatePath string) error
func (*Application) Route ¶
func (application *Application) Route(controller interface{}, route string) web.HandlerFunc
type Controller ¶
type Controller struct { }
func (*Controller) CheckPasswordResetToken ¶
func (controller *Controller) CheckPasswordResetToken(tokenStr string, c web.C) (models.UserToken, *models.PasswordReset, bool)
CheckPasswordResetToken checks that the input token string is valid, recognized by the DB, and not expired. Flash messages are added to the session for any token failure, and the return indicates if all checks have passed. The UserToken and PasswordReset objects are also returned.
func (*Controller) GetSession ¶
func (controller *Controller) GetSession(c web.C) *sessions.Session
func (*Controller) GetTemplate ¶
func (controller *Controller) GetTemplate(c web.C) *template.Template
func (*Controller) IsCaptchaDone ¶
func (controller *Controller) IsCaptchaDone(c web.C) bool
type SQLStore ¶
SQLStore stores gorilla sessions in a database.
func NewSQLStore ¶
func NewSQLStore(ctx context.Context, wg *sync.WaitGroup, dbMap *gorp.DbMap, keyPairs ...[]byte) *SQLStore
NewSQLStore returns a new SQLStore. The keyPairs are used in the same way as the gorilla sessions CookieStore.