Documentation
¶
Index ¶
- Constants
- type App
- func (app *App) AuthCallback(w http.ResponseWriter, r *http.Request)
- func (app *App) HomeGET(w http.ResponseWriter, r *http.Request)
- func (app *App) LogoutGET(w http.ResponseWriter, r *http.Request)
- func (app *App) RequireLogin(next http.Handler) http.Handler
- func (app *App) Start()
- func (app *App) Stop(ctx context.Context) error
- func (app *App) UserDELETE(w http.ResponseWriter, r *http.Request)
- func (app *App) UserEditGET(w http.ResponseWriter, r *http.Request)
- func (app *App) UserGET(w http.ResponseWriter, r *http.Request)
- func (app *App) UserNewGET(w http.ResponseWriter, r *http.Request)
- func (app *App) UserPOST(w http.ResponseWriter, r *http.Request)
- func (app *App) UserPUT(w http.ResponseWriter, r *http.Request)
- func (app *App) UsersGET(w http.ResponseWriter, r *http.Request)
- type Config
- type ContentType
- type Environment
- type HTMLParams
- type Renderer
- func (r *Renderer) Data(w http.ResponseWriter, req *http.Request, status int, v []byte) error
- func (r *Renderer) Error(w http.ResponseWriter, req *http.Request, status int, err error)
- func (r *Renderer) HTML(w http.ResponseWriter, req *http.Request, params HTMLParams) error
- func (r *Renderer) HTMLError(w http.ResponseWriter, req *http.Request, status int, err error)
- func (r *Renderer) JSON(w http.ResponseWriter, req *http.Request, status int, v interface{}) error
- func (r *Renderer) JSONError(w http.ResponseWriter, req *http.Request, status int, err error)
- func (r *Renderer) JSONP(w http.ResponseWriter, req *http.Request, status int, callback string, ...) error
- func (r *Renderer) Redirect(w http.ResponseWriter, req *http.Request, url string, status int)
- func (r *Renderer) Text(w http.ResponseWriter, req *http.Request, status int, v string) error
- func (r *Renderer) XML(w http.ResponseWriter, req *http.Request, status int, v interface{}) error
Constants ¶
const ( ContentTypeHTML = iota ContentTypeJSON )
const ( DevelopmentEnvironment Environment = "development" TestEnvironment = "test" ProductionEnvironment = "production" )
const CookieLifetime = 2 * time.Hour
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) AuthCallback ¶
func (app *App) AuthCallback(w http.ResponseWriter, r *http.Request)
func (*App) HomeGET ¶
func (app *App) HomeGET(w http.ResponseWriter, r *http.Request)
HomeGET is a default handler to serve up a home page.
func (*App) RequireLogin ¶
RequireLogin checks whether or not a user is logged in with an unexpired session cookie if the user is not logged in, then the frontend should redirect to /auth/google
func (*App) Start ¶
func (app *App) Start()
Start begins listening for connections and serving clients in the background.
func (*App) Stop ¶
Stop gracefully shuts down the server and closes the database. Set a timeout on the provided context to force shutdown after a certain amount of time.
func (*App) UserDELETE ¶
func (app *App) UserDELETE(w http.ResponseWriter, r *http.Request)
UserDELETE handles DELETE /users/{id}
func (*App) UserEditGET ¶
func (app *App) UserEditGET(w http.ResponseWriter, r *http.Request)
UserEditGET handles GET /users/{id}/edit
func (*App) UserGET ¶
func (app *App) UserGET(w http.ResponseWriter, r *http.Request)
UserGET handles GET /users/{id}
func (*App) UserNewGET ¶
func (app *App) UserNewGET(w http.ResponseWriter, r *http.Request)
UserNewGET handles GET /users/new
func (*App) UserPOST ¶
func (app *App) UserPOST(w http.ResponseWriter, r *http.Request)
UserPOST handles POST /users
type Config ¶
type Config struct {
ServerAddr string `envconfig:"SERVER_ADDR"`
SessionSecret string `envconfig:"SESSION_SECRET"`
DeployEnv Environment `envconfig:"DEPLOY_ENV"`
EnforceAuth bool `envconfig:"ENFORCE_AUTH"`
SiteURL string `envconfig:"SITE_URL"`
DBConfig models.Config `envconfig:"DB"`
GoogleOAuthKey string `envconfig:"GOOGLE_OAUTH_KEY"`
GoogleOAuthSecret string `envconfig:"GOOGLE_OAUTH_SECRET"`
}
type ContentType ¶
type ContentType int
func GetContentType ¶
func GetContentType(r *http.Request) ContentType
GetContentType figures out which of the above supported content/media types we should use with our request, by checking first the "Content-Type" header, or falling back to the "Accept" header. Use it like so:
switch GetContentType(r) {
case ContentTypeHTML:
// Render the response as HTML data
case ContentTypeJSON:
// Render JSON
}
type Environment ¶
type Environment string
func (Environment) IsProduction ¶
func (e Environment) IsProduction() bool
type HTMLParams ¶
type HTMLParams struct {
// HTTP Status, defaults to http.StatusOK (200).
Status int
// Name of the template to render, e.g. "users/new" for templates/users/new.html.
Template string
// Data to pass to the template, often a map of key/values.
Data any
// Options for the renderer.
HTMLOptions []render.HTMLOptions
// A page title used by the layout.
Title string
}
HTMLParams provides all the HTML function needs to render an HTML template.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer wraps the unrolled/render package in order to provide a few goodies (error rendering, session saving).
func NewRenderer ¶
func (*Renderer) Error ¶
Error figures out how to render the given error message appropriate to the expected content type, while showing full error messages in dev but not in production.
func (*Renderer) HTML ¶
func (r *Renderer) HTML(w http.ResponseWriter, req *http.Request, params HTMLParams) error
HTML builds up the response from the specified parameters.
func (*Renderer) HTMLError ¶
HTMLError sends the user an HTML error page, hiding error details in production.
func (*Renderer) JSONError ¶
HTMLError sends the user a JSON error payload, hiding error details in production.
func (*Renderer) JSONP ¶
func (r *Renderer) JSONP(w http.ResponseWriter, req *http.Request, status int, callback string, v interface{}) error
JSONP marshals the given interface object and writes the JSON response.