web

package
v0.0.0-...-f98e9bb Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderContentType     string = "Content-Type"
	HeaderCacheControl    string = "Cache-Control"
	HeaderContentEncoding string = "Content-Encoding"
	HeaderAcceptEncoding  string = "Accept-Encoding"
)
View Source
const (
	MimeTypeJson string = "application/json; charset=utf-8"
	MimeTypeHtml string = "text/html; charset=utf-8"
)
View Source
const CacheOneYear = 24 * time.Hour * 365
View Source
const (
	CookieSession = "s"
)
View Source
const HistoryKey = "history"

Variables

This section is empty.

Functions

func Helmet

func Helmet(ctx Context, next Handler)

func InitContext

func InitContext(w http.ResponseWriter, r *http.Request, next Handler)

func Recover

func Recover(ctx Context, next Handler)

func RequestLogger

func RequestLogger(ctx Context, next Handler)

Types

type Authenticated

type Authenticated struct {
	// contains filtered or unexported fields
}

func NewAuthenticatedMiddleware

func NewAuthenticatedMiddleware(sessionService session.Service) *Authenticated

func (*Authenticated) Middleware

func (middleware *Authenticated) Middleware(ctx Context, next Handler)

type BaseModel

type BaseModel struct {
	// contains filtered or unexported fields
}

func (*BaseModel) Theme

func (base *BaseModel) Theme() string

func (*BaseModel) Version

func (base *BaseModel) Version() string

type CacheOption

type CacheOption byte
const (
	NoCache CacheOption = 1 << iota
	MustRevalidate
	NoStore
	Private
	Public
	Immutable
)

func (CacheOption) IsSet

func (flags CacheOption) IsSet(option CacheOption) bool

type Compression

type Compression struct {
	Middleware
}

func CompressionMiddleware

func CompressionMiddleware() *Compression

type Config

type Config struct {
	Host string    `json:"host" env:"UNIOND_WEB_HOST" validate:"hostname|ip"`
	Port int       `json:"port" env:"UNIOND_WEB_PORT" validate:"gt=0,lte=65536"`
	Tls  TlsConfig `json:"tls"`
}

func DefaultConfig

func DefaultConfig() Config

func (Config) Addr

func (conf Config) Addr() string

func (Config) Url

func (conf Config) Url() string

type Context

type Context interface {
	session.Session

	WithSession(session.Session) Context
	WithResponseWriter(http.ResponseWriter) Context

	Version() string

	PathValue(param string) string
	QueryValue(param string) string
	Redirect(path string)
	RedirectBackOr(fallback string)
	SignOut(redirect string)
	Json(data any)
	Html(html []byte)
	HttpError(err error)
	GetSessionCookie() (*common.Ulid, error)
	CacheControl(maxAge time.Duration, options CacheOption)
	SetCookie(*http.Cookie)
	ServeFileFS(files fs.FS, name string)
	RequestHeader() http.Header
	ResponseHeader() http.Header
	FormValues() url.Values
	ParseForm() (common.M, error)
	Method() string
	Url() *url.URL
	// contains filtered or unexported methods
}

func MustContext

func MustContext(r *http.Request) Context

func NewContext

func NewContext(session session.Session, version string, w http.ResponseWriter, r *http.Request) Context

type Controller

type Controller struct {
	dig.Out

	*Route `group:"routes"`
}

type Controllers

type Controllers struct {
	dig.In

	Routes []*Route `group:"routes"`
}

type Handler

type Handler func(ctx Context)

func FromHttpHandler

func FromHttpHandler(handler http.Handler) Handler

type History

type History struct {
	// contains filtered or unexported fields
}

func HistoryMiddleware

func HistoryMiddleware(sessionService session.Service) *History

func (*History) Middleware

func (history *History) Middleware(ctx Context, next Handler)

type Middleware

type Middleware func(ctx Context, next Handler)

func (Middleware) Name

func (middleware Middleware) Name() string

type Model

type Model interface {
	Version() string
	Theme() string
	// contains filtered or unexported methods
}

type PasskeyAlg

type PasskeyAlg int
const (
	AlgEdDsa PasskeyAlg = -8
	AlgEs256 PasskeyAlg = -7
	AlgRs256 PasskeyAlg = -257
)

type PasskeyCreationOptions

type PasskeyCreationOptions struct {
	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions
	PublicKey PasskeyPubKey `json:"publicKey"`
}

type PasskeyPubKey

type PasskeyPubKey struct {
	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#attestation
	// one of: "none", "direct", "enterprise", "indirect"
	Attestation *string `json:"attestation,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#attestationformats
	AttestationFormats *[]string `json:"attestationFormats,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#authenticatorselection
	AuthenticatorSelection *PasskeyPubKeyAuthenticatorSelection `json:"authenticatorSelection,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#challenge
	// base64url encoding of an underlying []byte
	Challenge string `json:"challenge"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#excludecredentials
	ExcludeCredentials *[]PasskeyPubKeyExcludeCredential `json:"excludeCredentials,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#extensions
	// TODO: https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/WebAuthn_extensions
	Extensions *any `json:"extensions,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#hints
	// one of: "security-key", "client-device", "hybrid"
	Hints *[]string `json:"hints,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#pubkeycredparams
	PubKeyCredParams []PasskeyPubKeyCredParam `json:"pubKeyCredParams"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp
	Rp PasskeyPubKeyRp `json:"rp"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#timeout
	Timeout *uint `json:"timeout,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#user
	User PasskeyPubKeyUser `json:"user"`
}

type PasskeyPubKeyAuthenticatorSelection

type PasskeyPubKeyAuthenticatorSelection struct {
	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#authenticatorattachment
	// one of: "platform", "cross-platform"
	AuthenticatorAttachment *string `json:"authenticatorAttachment,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#requireresidentkey
	RequireResidentKey *bool `json:"requireResidentKey,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#residentkey
	// one of: "discouraged", "preferred", "required"
	ResidentKey *string `json:"residentKey,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#userverification
	// one of: "discouraged", "preferred", "required"
	UserVerification *string `json:"userVerification,omitempty"`
}

type PasskeyPubKeyCredParamType

type PasskeyPubKeyCredParamType string
const (
	PasskeyPubKeyType PasskeyPubKeyCredParamType = "public-key"
)

type PasskeyPubKeyExcludeCredential

type PasskeyPubKeyExcludeCredential struct {
	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#id
	Id string `json:"id"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#transports
	// one of: "ble", "hybrid", "internal", "nfc", "usb"
	Transports *[]string `json:"transports,omitempty"`

	// https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#type
	// literal: "public-key"
	Type PasskeyPubKeyCredParamType `json:"type"`
}

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

func NewRenderer

func NewRenderer(files fs.FS) (*Renderer, error)

func (*Renderer) Render

func (renderer *Renderer) Render(ctx Context, page string, model Model) ([]byte, error)

type Route

type Route struct {
	Pattern    string
	Middleware []Middleware
	Handler    Handler
	View       string
	Model      func(ctx Context) (model Model, err error)
	Renderer   *Renderer
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(
	name string,
	conf *Config,
	controller Controllers,
	globalMiddleware []Middleware,
) (*Server, common.Closer, error)

func (Server) Start

func (server Server) Start()

start the https server

type Session

type Session struct {
	// contains filtered or unexported fields
}

func SessionMiddleware

func SessionMiddleware(
	sessionService session.Service,
	localsService locals.MemberService,
) *Session

func (*Session) Middleware

func (middleware *Session) Middleware(ctx Context, next Handler)

type TlsConfig

type TlsConfig struct {
	Enabled bool `json:"enabled" env:"UNIOND_WEB_TLS_ENABLED"`
}

Jump to

Keyboard shortcuts

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