libhttp

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: AGPL-3.0 Imports: 11 Imported by: 0

README

libhttp

Documentation

Index

Constants

View Source
const (
	HeaderAccept                    = "Accept"
	HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowOrigin  = "Access-Control-Allow-Origin"
	HeaderContentType               = "Content-Type"
	HeaderPermissionsPolicy         = "Permissions-Policy"

	MimeApplicationActivityJSON = `application/activity+json`
	MimeApplicationJrdJSON      = `application/jrd+json`
	MimeApplicationJSON         = `application/json`
	MimeApplicationXML          = `application/xml`
	MimeTextHTML                = `text/html`
	MimeTextPlain               = `text/plain`

	PermissionsPolicyBlockFLOC = "interest-cohort=()"
)

Variables

View Source
var (
	ErrMalformedAccept = errors.New("malformed Accept header")
)

Functions

func Accepts

func Accepts(r *http.Request, defaultAccept string, validAccepts ...string) (string, int, error)

func PageLang

func PageLang(query, header, defaultLang string) string

func PaginationFromRequest

func PaginationFromRequest(r *http.Request, defaultCount int) (int, int)

func ReturnJSONError

func ReturnJSONError(w http.ResponseWriter, status int, errStr string, vars ...interface{}) error

Types

type Authorization

type Authorization interface {
	// AuthID returns a unique identifier for this account/user
	AuthID() string
	// Username returns the preferred username
	Username() string
	// Groups returns the resolved group memberships
	Groups() []string
}

type Authorizer

type Authorizer[S Server] interface {
	Module[S]

	RequireAuth(r *http.Request) (Authorization, int, error)
}

type Module

type Module[S Server] interface {
	Name() string
	Route(s S) error
}

type Server

type Server interface {
	HandleFunc(path string, f func(http.ResponseWriter, *http.Request)) *mux.Route
}

Directories

Path Synopsis
auth

Jump to

Keyboard shortcuts

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