notificationsapp: Index | Files | Directories

package notificationsapp

import ""

Package notificationsapp is a web frontend for a notifications service.

Note, the canonical issue tracker for this package is currently hosted at Its notifications are implemented using this very package.


Package Files

doc.go errorhandler.go main.go


var BaseURIContextKey = &contextKey{"BaseURI"}

BaseURIContextKey is a context key for the request's base URI. That value specifies the base URI prefix to use for all absolute URLs. The associated value will be of type string.

func New Uses

func New(service notifications.Service, users users.Service, opt Options) http.Handler

New returns a notifications app http.Handler using given services and options. It uses users service, if not nil, when displaying errors (admins see full details).

In order to serve HTTP requests, the returned http.Handler expects each incoming request to have a parameter provided to it via BaseURIContextKey context key. For example:

notificationsApp := notificationsapp.New(...)

http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
	req = req.WithContext(context.WithValue(req.Context(), notificationsapp.BaseURIContextKey, string(...)))
	notificationsApp.ServeHTTP(w, req)

An HTTP API must be available:

// Register HTTP API endpoints.
apiHandler := httphandler.Notifications{Notifications: service}
http.Handle(httproute.MarkRead, errorHandler(apiHandler.MarkRead))
http.Handle(httproute.MarkAllRead, errorHandler(apiHandler.MarkAllRead))

type Options Uses

type Options struct {
    HeadPre template.HTML
    BodyPre template.HTML

    // BodyTop provides components to include on top of <body> of page rendered for req. It can be nil.
    BodyTop func(req *http.Request) ([]htmlg.Component, error)

Options for configuring notifications app.


assetsPackage assets contains assets for notificationsapp.
componentPackage component contains individual components that can render themselves as HTML.
frontendfrontend script for notificationsapp.
httpclientPackage httpclient contains notifications.Service implementation over HTTP.
httphandlerPackage httphandler contains an API handler for notifications.Service.
httproutePackage httproute contains route paths for httpclient, httphandler.

Package notificationsapp imports 18 packages (graph) and is imported by 2 packages. Updated 2018-11-21. Refresh now. Tools for package owners.