cutil

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Package cutil - Content managed by Project Forge, see [projectforge.md] for details.

Index

Constants

View Source
const (
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	HeaderAccessControlAllowHeaders     = "Access-Control-Allow-Headers"
	HeaderAccessControlAllowMethods     = "Access-Control-Allow-Methods"
	HeaderAccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	HeaderAccessControlExposeHeaders    = "Access-Control-Expose-Headers"
	HeaderCacheControl                  = "Cache-Control"
	HeaderContentType                   = "Content-Type"
	HeaderReferer                       = "Referer"
)
View Source
const (
	DefaultSearchPath  = "/search"
	DefaultProfilePath = "/profile"
)
View Source
const (
	PageComment = "Thanks for viewing the source; we tried to make it pretty for you"
)

Variables

View Source
var (
	AllowedRequestHeaders  = "*"
	AllowedResponseHeaders = "*"
)
View Source
var AppRoutesList = map[string][]string{}
View Source
var (
	MaxBodySize = int64(1024 * 1024 * 128) // 128MB
)

Functions

func AddRoute added in v1.2.0

func AddRoute(method string, path string)

func CleanID added in v0.8.0

func CleanID(key string, id string) string

func FormatFilename

func FormatFilename(content string, filename string) (string, error)

func FormatJSON

func FormatJSON(v any) (string, error)

func FormatLang

func FormatLang(content string, lang string) (string, error)

func FormatMarkdown added in v0.7.5

func FormatMarkdown(s string) (string, error)

func FormatMarkdownClean added in v1.0.6

func FormatMarkdownClean(s string, icon string) (string, string, error)

func FormatString

func FormatString(content string, l chroma.Lexer) (string, error)

func GetContentType

func GetContentType(r *http.Request) string

func IsContentTypeCSV added in v1.1.0

func IsContentTypeCSV(c string) bool

func IsContentTypeDebug added in v1.1.0

func IsContentTypeDebug(c string) bool

func IsContentTypeJSON

func IsContentTypeJSON(c string) bool

func IsContentTypeXML

func IsContentTypeXML(c string) bool

func IsContentTypeYAML

func IsContentTypeYAML(c string) bool

func ParamSetFromRequest

func ParamSetFromRequest(r *http.Request) filter.ParamSet

func ParseForm

func ParseForm(r *http.Request, b []byte) (util.ValueMap, error)

func ParseFormAsChanges

func ParseFormAsChanges(r *http.Request, b []byte) (util.ValueMap, error)

func QueryArgsMap added in v0.11.6

func QueryArgsMap(r *http.Request) util.ValueMap

func QueryStringBool added in v0.2.38

func QueryStringBool(r *http.Request, key string) bool

func RCRequiredArray added in v0.6.15

func RCRequiredArray(r *http.Request, key string) ([]string, error)

func RCRequiredBool added in v0.2.38

func RCRequiredBool(r *http.Request, key string) (bool, error)

func RCRequiredInt added in v0.2.38

func RCRequiredInt(r *http.Request, key string) (int, error)

func RCRequiredString added in v0.2.38

func RCRequiredString(r *http.Request, key string, allowEmpty bool) (string, error)

func RCRequiredUUID added in v0.2.38

func RCRequiredUUID(r *http.Request, key string) (*uuid.UUID, error)

func RequestCtxToMap

func RequestCtxToMap(w http.ResponseWriter, r *http.Request, as *app.State, ps *PageState) util.ValueMap

func RequestHeadersMap added in v0.11.6

func RequestHeadersMap(r *http.Request) util.ValueMap

func RespondCSV added in v1.1.0

func RespondCSV(w http.ResponseWriter, filename string, body any) (string, error)

func RespondDebug

func RespondDebug(w http.ResponseWriter, r *http.Request, as *app.State, filename string, ps *PageState) (string, error)

func RespondJSON

func RespondJSON(w http.ResponseWriter, filename string, body any) (string, error)

func RespondMIME

func RespondMIME(filename string, mime string, ext string, ba []byte, w http.ResponseWriter) (string, error)

func RespondXML

func RespondXML(w http.ResponseWriter, filename string, body any) (string, error)

func RespondYAML

func RespondYAML(w http.ResponseWriter, filename string, body any) (string, error)

func ResponseHeadersMap added in v0.11.6

func ResponseHeadersMap(w http.ResponseWriter) util.ValueMap

func URLAddQuery added in v1.2.1

func URLAddQuery(u *url.URL, k string, v string)

func WireRouter added in v1.2.0

func WireRouter(r *mux.Router, notFound http.HandlerFunc, logger util.Logger) (http.Handler, error)

func WriteCORS

func WriteCORS(w http.ResponseWriter)

Types

type Arg

type Arg struct {
	Key         string   `json:"key"`
	Title       string   `json:"title"`
	Description string   `json:"description,omitempty"`
	Type        string   `json:"type,omitempty"`
	Default     string   `json:"default,omitempty"`
	Choices     []string `json:"choices,omitempty"`
}

type ArgResults

type ArgResults struct {
	Args    Args          `json:"args"`
	Values  util.ValueMap `json:"values"`
	Missing []string      `json:"missing,omitempty"`
}

func CollectArgs

func CollectArgs(r *http.Request, args Args) *ArgResults

func (*ArgResults) HasMissing added in v0.10.8

func (a *ArgResults) HasMissing() bool

type Args

type Args []*Arg

type Location

type Location struct {
	URL   string `json:"url"`
	Title string `json:"title"`
	Icon  string `json:"icon,omitempty"`
}

type Locations

type Locations []*Location

type PageState

type PageState struct {
	Action         string            `json:"action,omitempty"`
	Title          string            `json:"title,omitempty"`
	Description    string            `json:"description,omitempty"`
	Method         string            `json:"method,omitempty"`
	URI            *url.URL          `json:"-"`
	Menu           menu.Items        `json:"menu,omitempty"`
	Breadcrumbs    cmenu.Breadcrumbs `json:"breadcrumbs,omitempty"`
	Flashes        []string          `json:"flashes,omitempty"`
	Session        util.ValueMap     `json:"-"`
	Profile        *user.Profile     `json:"profile,omitempty"`
	Authed         bool              `json:"authed,omitempty"`
	Admin          bool              `json:"admin,omitempty"`
	Params         filter.ParamSet   `json:"params,omitempty"`
	Icons          []string          `json:"icons,omitempty"`
	DefaultNavIcon string            `json:"defaultNavIcon,omitempty"`
	RootIcon       string            `json:"rootIcon,omitempty"`
	RootPath       string            `json:"rootPath,omitempty"`
	RootTitle      string            `json:"rootTitle,omitempty"`
	SearchPath     string            `json:"searchPath,omitempty"`
	ProfilePath    string            `json:"profilePath,omitempty"`
	HideMenu       bool              `json:"hideMenu,omitempty"`
	ForceRedirect  string            `json:"forceRedirect,omitempty"`
	HeaderContent  string            `json:"headerContent,omitempty"`
	Browser        string            `json:"browser,omitempty"`
	BrowserVersion string            `json:"browserVersion,omitempty"`
	OS             string            `json:"os,omitempty"`
	OSVersion      string            `json:"osVersion,omitempty"`
	Platform       string            `json:"platform,omitempty"`
	Data           any               `json:"data,omitempty"`
	Started        time.Time         `json:"started,omitempty"`
	RenderElapsed  float64           `json:"renderElapsed,omitempty"`
	RequestBody    []byte            `json:"-"`
	Logger         util.Logger       `json:"-"`
	Context        context.Context   `json:"-"` //nolint:containedctx // properly closed, never directly used
	Span           *telemetry.Span   `json:"-"`
}

func LoadPageState added in v0.3.15

func LoadPageState(as *app.State, w http.ResponseWriter, r *http.Request, key string, logger util.Logger) *PageState

func (*PageState) AddIcon

func (p *PageState) AddIcon(keys ...string)

func (*PageState) ClassDecl added in v0.10.12

func (p *PageState) ClassDecl() string

func (*PageState) Clean added in v0.3.15

func (p *PageState) Clean(_ *http.Request, as *app.State) error

func (*PageState) Close

func (p *PageState) Close()

func (*PageState) LogError added in v0.11.14

func (p *PageState) LogError(msg string, args ...any)

func (*PageState) SetTitleAndData added in v1.0.7

func (p *PageState) SetTitleAndData(title string, data any)

func (*PageState) TitleString

func (p *PageState) TitleString() string

func (*PageState) Username added in v0.8.17

func (p *PageState) Username() string

type XMLResponse

type XMLResponse struct {
	Result any `xml:"result"`
}

Jump to

Keyboard shortcuts

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