README

notificationsapp

Go Reference Build Status

Package notificationsapp is a web frontend for a notifications service.

Note, the canonical issue tracker for this package is currently hosted at https://dmitri.shuralyov.com/issues/github.com/shurcooL/notificationsapp. Its notifications are implemented using this very package.

Installation

go get github.com/shurcooL/notificationsapp

Development

This package relies on go generate directives to process and statically embed assets. For development only, you may need extra dependencies. You can build and run the package in development mode, where all assets are always read and processed from disk:

go build -tags=notificationsappdev something/that/uses/notificationsapp

When you're done with development, you should run go generate and commit that:

go generate github.com/shurcooL/notificationsapp/...

Directories

Path Synopsis
assets Package assets contains assets for notificationsapp.
component Package component contains individual components that can render themselves as HTML.
frontend frontend script for notificationsapp.
httpclient Package httpclient contains notifications.Service implementation over HTTP.
httphandler Package httphandler contains an API handler for notifications.Service.
httproute Package httproute contains route paths for httpclient, httphandler.

License

Expand ▾ Collapse ▴

Documentation

Overview

    Package notificationsapp is a web frontend for a notifications service.

    Note, the canonical issue tracker for this package is currently hosted at https://dmitri.shuralyov.com/issues/github.com/shurcooL/notificationsapp. Its notifications are implemented using this very package.

    Index

    Constants

    This section is empty.

    Variables

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

      Functions

      func New

      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))
        

        Types

        type Options

        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.

          Directories

          Path Synopsis
          Package assets contains assets for notificationsapp.
          Package assets contains assets for notificationsapp.
          Package component contains individual components that can render themselves as HTML.
          Package component contains individual components that can render themselves as HTML.
          frontend script for notificationsapp.
          frontend script for notificationsapp.
          Package httpclient contains notifications.Service implementation over HTTP.
          Package httpclient contains notifications.Service implementation over HTTP.
          Package httphandler contains an API handler for notifications.Service.
          Package httphandler contains an API handler for notifications.Service.
          Package httproute contains route paths for httpclient, httphandler.
          Package httproute contains route paths for httpclient, httphandler.