issuesapp

package module
v0.0.0-...-80666a8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 31 Imported by: 4

README

issuesapp

Go Reference

Package issuesapp is a web frontend for an issues service.

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

Installation

go get github.com/shurcooL/issuesapp

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=issuesappdev something/that/uses/issuesapp

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

go generate github.com/shurcooL/issuesapp/...

Directories

Path Synopsis
assets Package assets contains assets for issuesapp.
cmd/githubissues githubissues is a simple test program for issuesapp that uses GitHub API-backed services.
common Package common contains common code for backend and frontend.
component Package component contains individual components that can render themselves as HTML.
frontend frontend script for issuesapp.
httpclient Package httpclient contains issues.Service implementation over HTTP.
httphandler Package httphandler contains an API handler for issues.Service.
httproute Package httproute contains route paths for httpclient, httphandler.

License

Documentation

Overview

Package issuesapp is a web frontend for an issues service.

Note, the canonical issue tracker for this package is currently hosted at https://dmitri.shuralyov.com/issues/github.com/shurcooL/issuesapp. It is 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.

View Source
var RepoSpecContextKey = &contextKey{"RepoSpec"}

RepoSpecContextKey is a context key for the request's repository specification. That value specifies which repo the issues are to be displayed for. The associated value will be of type issues.RepoSpec.

View Source
var StateContextKey = &contextKey{"State"}

StateContextKey is a context key for the request's common state. That value specifies the common state of the page being rendered. The associated value will be of type common.State.

Functions

func New

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

New returns an issues app http.Handler using given services and options. If usersService is nil, then there is no way to have an authenticated user. Emojis image data is expected to be available at /emojis/emojis.png, unless opt.DisableReactions is true.

In order to serve HTTP requests, the returned http.Handler expects each incoming request to have 2 parameters provided to it via RepoSpecContextKey and BaseURIContextKey context keys. For example:

issuesApp := issuesapp.New(...)

http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
	req = req.WithContext(context.WithValue(req.Context(), issuesapp.RepoSpecContextKey, issues.RepoSpec{...}))
	req = req.WithContext(context.WithValue(req.Context(), issuesapp.BaseURIContextKey, string(...)))
	issuesApp.ServeHTTP(w, req)
})

An HTTP API must be available (currently, only EditComment endpoint is used):

// Register HTTP API endpoints.
apiHandler := httphandler.Issues{Issues: service}
http.Handle(httproute.List, errorHandler(apiHandler.List))
http.Handle(httproute.Count, errorHandler(apiHandler.Count))
http.Handle(httproute.ListComments, errorHandler(apiHandler.ListComments))
http.Handle(httproute.ListEvents, errorHandler(apiHandler.ListEvents))
http.Handle(httproute.EditComment, errorHandler(apiHandler.EditComment))

Types

type Options

type Options struct {
	Notifications    notifications.Service // If not nil, issues containing unread notifications are highlighted.
	DisableReactions bool                  // Disable all support for displaying and toggling reactions.

	HeadPre, HeadPost template.HTML
	BodyPre           string // An html/template definition of "body-pre" template.

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

	// SignIn returns HTML with a link or button to sign in. It can be nil.
	SignIn func(returnURL string) template.HTML
}

Options for configuring issues app.

Directories

Path Synopsis
Package assets contains assets for issuesapp.
Package assets contains assets for issuesapp.
cmd
githubissues
githubissues is a simple test program for issuesapp that uses GitHub API-backed services.
githubissues is a simple test program for issuesapp that uses GitHub API-backed services.
Package common contains common code for backend and frontend.
Package common contains common code for backend and frontend.
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 issuesapp.
frontend script for issuesapp.
Package httpclient contains issues.Service implementation over HTTP.
Package httpclient contains issues.Service implementation over HTTP.
Package httphandler contains an API handler for issues.Service.
Package httphandler contains an API handler for issues.Service.
Package httproute contains route paths for httpclient, httphandler.
Package httproute contains route paths for httpclient, httphandler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL