webcontroller

package
v0.0.0-...-2c1aa92 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackgroundTiles

func BackgroundTiles() template.URL

Types

type CSS

type CSS interface {
	CSS() string
}

type Color

type Color interface {
	CSS
	HSL() HSL
	RGB() RGB
}

type Config

type Config struct {
	APIURLExternal      string `toml:"api_url_external"`
	APIURLInternal      string `toml:"api_url_internal"`
	APISocketPath       string `toml:"api_socket_path"`
	SessionCookieDomain string `toml:"session_cookie_domain"`
	ResourceDir         string `toml:"resource_dir"`
	DebugMode           bool   `toml:"debug_mode"`
	ProxyAPIRequests    bool   `toml:"proxy_api_requests"`
	MaintenanceMode     bool   `toml:"maintenance_mode"`
}

type ExtraActions

type ExtraActions struct {
	// Redirects the browser to a different URL with a HTTP 303: See Other
	// status. This is useful for redirecting the user to a different page if
	// the form submission was successful
	RedirectTo string

	// A cookie to install in the browser when the form is rendered. Useful for
	// setting / destroying user sessions or configurations
	SetCookie *http.Cookie
}

ExtraActions contains extra actions to performs when rendering the form

type Field

type Field struct {
	// Used for reading the data. Entered data is POSTed back to the same URL with this name
	Name string

	// Is entered in the input field by default. If this is empty when running
	// Form.ReadInput() it will be set to the value entered by the user
	DefaultValue string

	// The value entered by the user. Filled in when running Form.ReadInput()
	EnteredValue string

	// Text next to the input field
	Label string

	// Text below the input field
	Description template.HTML

	Type FieldType

	// Only used when Type == FieldTypeCaptcha
	CaptchaSiteKey string

	// Only used when Type == FieldTypeRadio
	RadioValues []string
}

Field is a single input field in a form

type FieldType

type FieldType string

FieldType defines the type a form field has and how it should be rendered

const (
	FieldTypeText            FieldType = "text"
	FieldTypeTextarea        FieldType = "textarea"
	FieldTypeNumber          FieldType = "number"
	FieldTypeUsername        FieldType = "username"
	FieldTypeEmail           FieldType = "email"
	FieldTypeRadio           FieldType = "radio"
	FieldTypeCurrentPassword FieldType = "current-password"
	FieldTypeNewPassword     FieldType = "new-password"
	FieldTypeCaptcha         FieldType = "captcha"
	FieldTypeDescription     FieldType = "description"
)

Fields which can be in a form

type Form

type Form struct {
	// Name of the form. When this form is submitted this name will be in the `form` parameter
	Name string

	Title       string        // Shown in a large font above the form
	PreFormHTML template.HTML // Content to be rendered above the form

	Fields []Field

	SubmitLabel string // Label for the submit button
	SubmitRed   bool   // If the submit button should be red or green

	PostFormHTML template.HTML // Content to be rendered below the form

	// Fields to render if the form has been submitted once
	Submitted      bool            // If the form has been submitted
	SubmitSuccess  bool            // If the submission was a success
	SubmitMessages []template.HTML // Messages telling the user the results

	// Used for letting the browser know which user is logged in
	Username string

	// Actions to perform when the form is rendered
	Extra ExtraActions
}

Form is a form which can be rendered in HTML and submitted

func (*Form) FieldVal

func (f *Form) FieldVal(name string) (enteredValue string)

FieldVal is a utility function for getting the entered value of a field by its name. By using this function you don't have to use nondescriptive array indexes to get the values. It panics if the field name is not found in the form

func (*Form) ReadInput

func (f *Form) ReadInput(r *http.Request) (success bool)

ReadInput reads the form of a request and fills in the values for each field. The return value will be true if this form was submitted and false if the form was not submitted

type Gradient

type Gradient struct {
	Angle  int
	Colors []Color
}

func NewGradient

func NewGradient(angle int, colors ...Color) Gradient

func (Gradient) CSS

func (g Gradient) CSS() string

type HSL

type HSL struct {
	Hue        int
	Saturation float64
	Lightness  float64
}

HSL color

func (HSL) Add

func (hsl HSL) Add(hue int, saturation float64, lightness float64) HSL

Add returns a NEW HSL struct, it doesn't modify the current one

func (HSL) CSS

func (hsl HSL) CSS() string

func (HSL) Darken

func (hsl HSL) Darken(percent float64) HSL

func (HSL) HSL

func (hsl HSL) HSL() HSL

func (HSL) RGB

func (hsl HSL) RGB() RGB

func (HSL) WithAlpha

func (hsl HSL) WithAlpha(alpha float64) HSLA

type HSLA

type HSLA struct {
	Hue        int
	Saturation float64
	Lightness  float64
	Alpha      float64
}

func (HSLA) CSS

func (hsla HSLA) CSS() string

func (HSLA) HSL

func (hsla HSLA) HSL() HSL

func (HSLA) RGB

func (hsla HSLA) RGB() RGB

type RGB

type RGB struct {
	R uint8
	G uint8
	B uint8
}

func (RGB) CSS

func (rgb RGB) CSS() string

func (RGB) HSL

func (rgb RGB) HSL() HSL

func (RGB) RGB

func (rgb RGB) RGB() RGB

type RGBA

type RGBA struct {
	R uint8
	G uint8
	B uint8
	A float64
}

func (RGBA) CSS

func (rgba RGBA) CSS() string

func (RGBA) HSL

func (rgba RGBA) HSL() HSL

func (RGBA) RGB

func (rgba RGBA) RGB() RGB

type RawCSS

type RawCSS string

Raw CSS

func (RawCSS) CSS

func (c RawCSS) CSS() string

type TemplateData

type TemplateData struct {
	Authenticated bool
	User          pixelapi.UserInfo
	UserAgent     string
	APIEndpoint   template.URL
	PixelAPI      pixelapi.PixelAPI
	Hostname      template.HTML

	// Only used on file viewer page
	Title  string
	OGData ogData

	Other    interface{}
	URLQuery url.Values

	// Only used for pages containing forms
	Form Form
	// contains filtered or unexported fields
}

TemplateData is a struct that every template expects when being rendered. In the field Other you can pass your own template-specific variables.

type TemplateManager

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

TemplateManager parses templates and provides utility functions to the templates' scripting language

func NewTemplateManager

func NewTemplateManager(resourceDir, externalAPIEndpoint string, debugMode bool) *TemplateManager

NewTemplateManager creates a new template manager

func (*TemplateManager) ParseTemplates

func (tm *TemplateManager) ParseTemplates(silent bool)

ParseTemplates parses the templates in the template directory which is defined in the config file. If silent is false it will print an info log message for every template found

func (*TemplateManager) Run

func (tm *TemplateManager) Run(w io.Writer, r *http.Request, name string, data any) (err error)

Run runs a template by name

type WebController

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

WebController controls how requests are handled and makes sure they have proper context when running

func New

func New(r *httprouter.Router, prefix string, conf Config) (wc *WebController)

New initializes a new WebController by registering all the request handlers and parsing all templates in the resource directory

Jump to

Keyboard shortcuts

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