Documentation ¶
Overview ¶
Package web contains utilities to help build out a web service.
Index ¶
- func HandleError(w http.ResponseWriter, err error, logger golog.Logger, context ...string) bool
- func InstallAuth0(ctx context.Context, mux *goji.Mux, sessions *SessionManager, ...) (io.Closer, error)
- func InstallFusionAuth(ctx context.Context, mux *goji.Mux, sessions *SessionManager, ...) (io.Closer, error)
- type APIHandler
- type APIMiddleware
- type AuthProvider
- type AuthProviderConfig
- type ErrorResponse
- type PanicCapture
- type Session
- type SessionManager
- type Store
- type Template
- type TemplateHandler
- type TemplateHandlerFunc
- type TemplateManager
- func NewTemplateManagerEmbed(fs fs.ReadDirFS, srcDir string) (TemplateManager, error)
- func NewTemplateManagerEmbedWithOptions(fs fs.ReadDirFS, srcDir string, opts protojson.MarshalingOptions) (TemplateManager, error)
- func NewTemplateManagerFS(srcDir string) (TemplateManager, error)
- func NewTemplateManagerFSWithOptions(srcDir string, opts protojson.MarshalingOptions) (TemplateManager, error)
- type TemplateMiddleware
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleError ¶
HandleError returns true if there was an error and you should stop.
func InstallAuth0 ¶
func InstallAuth0( ctx context.Context, mux *goji.Mux, sessions *SessionManager, config AuthProviderConfig, logger golog.Logger, ) (io.Closer, error)
InstallAuth0 does initial setup and installs routes for auth0.
func InstallFusionAuth ¶ added in v0.1.55
func InstallFusionAuth( ctx context.Context, mux *goji.Mux, sessions *SessionManager, config AuthProviderConfig, logger golog.Logger, ) (io.Closer, error)
InstallFusionAuth does initial setup and installs routes for FusionAuth.
Types ¶
type APIHandler ¶
type APIHandler interface { // return (result, error) // if both are null, do nothing ServeAPI(w http.ResponseWriter, r *http.Request) (interface{}, error) }
APIHandler what a user has to implement to use APIMiddleware.
type APIMiddleware ¶
type APIMiddleware struct { protojson.MarshalingOptions Handler APIHandler Logger golog.Logger // Recover from panics with a proper error logs. PanicCapture }
APIMiddleware simple layer between http.Handler interface that does json marshalling and error handling.
func NewAPIMiddleware ¶ added in v0.0.6
func NewAPIMiddleware(h APIHandler, logger golog.Logger) *APIMiddleware
NewAPIMiddleware returns a configured APIMiddleware with a panic capture configured.
func (*APIMiddleware) ServeHTTP ¶
func (am *APIMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP call the api.
type AuthProvider ¶ added in v0.1.55
AuthProvider should include all state that we need to share with auth callbacks or to make customizations on the internals of the specific auth mechanisms we implement for a particular provider.
func (*AuthProvider) Close ¶ added in v0.1.55
func (s *AuthProvider) Close() error
Close called by io.Closer.
type AuthProviderConfig ¶ added in v0.1.55
type AuthProviderConfig struct { Domain string ClientID string Secret string BaseURL string PostLogoutRedirectURL string EnableTest bool }
AuthProviderConfig config options with constants that will probably need to be manually configured after retrieval from the auth provider web UI or API (e.g. for Auth0, FusionAuth).
type ErrorResponse ¶
ErrorResponse lets you specify a status code.
func ErrorResponseStatus ¶
func ErrorResponseStatus(code int) ErrorResponse
ErrorResponseStatus creates an error response with a specific code.
type PanicCapture ¶ added in v0.0.6
PanicCapture allows recovery during a request handler from panics. It prints a formatted log to the underlying logger.
func (*PanicCapture) Recover ¶ added in v0.0.6
func (p *PanicCapture) Recover(w http.ResponseWriter, r *http.Request)
Recover captures and prints the error if recover() has an error.
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager handles working with sessions from http.
func NewSessionManager ¶
func NewSessionManager(theStore Store, logger golog.Logger) *SessionManager
NewSessionManager creates a new SessionManager.
func (*SessionManager) DeleteSession ¶
func (sm *SessionManager) DeleteSession(ctx context.Context, r *http.Request, w http.ResponseWriter)
DeleteSession deletes a session.
type Store ¶
type Store interface { Delete(ctx context.Context, id string) error Get(ctx context.Context, id string) (*Session, error) Save(ctx context.Context, s *Session) error SetSessionManager(*SessionManager) }
Store actually stores raw data somewhere.
func NewMemorySessionStore ¶
func NewMemorySessionStore() Store
NewMemorySessionStore creates a new memory session store.
func NewMongoDBSessionStore ¶
NewMongoDBSessionStore new MongoDB backed store.
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template specifies which template to render.
func DirectTemplate ¶
DirectTemplate creates a template to say use this specific template.
func NamedTemplate ¶
NamedTemplate creates a Template with a name.
type TemplateHandler ¶
type TemplateHandler interface { // return (template name, thing to pass to template, error) Serve(w http.ResponseWriter, r *http.Request) (*Template, interface{}, error) }
TemplateHandler implement this to be able to use middleware.
type TemplateHandlerFunc ¶
type TemplateHandlerFunc func(w http.ResponseWriter, r *http.Request) (*Template, interface{}, error)
TemplateHandlerFunc the func version of the handler.
func (TemplateHandlerFunc) Serve ¶
func (f TemplateHandlerFunc) Serve(w http.ResponseWriter, r *http.Request) (*Template, interface{}, error)
Serve does the work.
type TemplateManager ¶
TemplateManager responsible for managing, caching, finding templates.
func NewTemplateManagerEmbed ¶
func NewTemplateManagerEmbed(fs fs.ReadDirFS, srcDir string) (TemplateManager, error)
NewTemplateManagerEmbed creates a TemplateManager from an embedded file system.
func NewTemplateManagerEmbedWithOptions ¶ added in v0.0.6
func NewTemplateManagerEmbedWithOptions(fs fs.ReadDirFS, srcDir string, opts protojson.MarshalingOptions) (TemplateManager, error)
NewTemplateManagerEmbedWithOptions creates a TemplateManager from an embedded file system. Allows optional protojson.MarshalingOptions.
func NewTemplateManagerFS ¶
func NewTemplateManagerFS(srcDir string) (TemplateManager, error)
NewTemplateManagerFS creates a new TemplateManager from the file system.
func NewTemplateManagerFSWithOptions ¶ added in v0.0.6
func NewTemplateManagerFSWithOptions(srcDir string, opts protojson.MarshalingOptions) (TemplateManager, error)
NewTemplateManagerFSWithOptions creates a new TemplateManager from the file system. Allows optional protojson.MarshalingOptions.
type TemplateMiddleware ¶
type TemplateMiddleware struct { Templates TemplateManager Handler TemplateHandler Logger golog.Logger // Recover from panics with a proper error logs. PanicCapture }
TemplateMiddleware handles the rendering of the template from the data and finding of the template.
func NewTemplateMiddleware ¶ added in v0.0.6
func NewTemplateMiddleware(template TemplateManager, h TemplateHandler, logger golog.Logger) *TemplateMiddleware
NewTemplateMiddleware returns a configured TemplateMiddleWare with a panic capture configured.
func (*TemplateMiddleware) ServeHTTP ¶
func (tm *TemplateMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
type UserInfo ¶
type UserInfo struct { LoggedIn bool `json:"loggedIn"` Properties map[string]interface{} `json:"properties"` }
UserInfo basic info about a user from a session.
func GetLoggedInUserInfo ¶
func GetLoggedInUserInfo(sessions *SessionManager, r *http.Request) (UserInfo, error)
GetLoggedInUserInfo figures out if the session is associated with a user.
func (*UserInfo) GetEmailVerified ¶
GetEmailVerified if the email h as been verified.
func (*UserInfo) GetUpdatedAt ¶ added in v0.1.39
GetUpdatedAt gets the timestamp indicating when the user's auth0 profile was last updated/modified.