Documentation ¶
Overview ¶
Package cutil - Content managed by Project Forge, see [projectforge.md] for details.
Index ¶
- Constants
- Variables
- func AddRoute(method string, path string)
- func CleanID(key string, id string) string
- func FormatFilename(content string, filename string) (string, error)
- func FormatJSON(v any) (string, error)
- func FormatLang(content string, lang string) (string, error)
- func FormatMarkdown(s string) (string, error)
- func FormatMarkdownClean(s string, icon string) (string, string, error)
- func FormatString(content string, l chroma.Lexer) (string, error)
- func GetContentType(r *http.Request) string
- func IsContentTypeCSV(c string) bool
- func IsContentTypeDebug(c string) bool
- func IsContentTypeJSON(c string) bool
- func IsContentTypeTOML(c string) bool
- func IsContentTypeXML(c string) bool
- func IsContentTypeYAML(c string) bool
- func ParamSetFromRequest(r *http.Request) filter.ParamSet
- func ParseForm(r *http.Request, b []byte) (util.ValueMap, error)
- func ParseFormAsChanges(r *http.Request, b []byte) (util.ValueMap, error)
- func ParseFormAsMaps(r *http.Request, rBody []byte) ([]util.ValueMap, error)
- func PathArray(r *http.Request, key string) ([]string, error)
- func PathBool(r *http.Request, key string) (bool, error)
- func PathInt(r *http.Request, key string) (int, error)
- func PathString(r *http.Request, key string, allowEmpty bool) (string, error)
- func PathUUID(r *http.Request, key string) (*uuid.UUID, error)
- func QueryArgsMap(r *http.Request) util.ValueMap
- func QueryStringBool(r *http.Request, key string) bool
- func RequestCtxToMap(r *http.Request, _ *app.State, ps *PageState) util.ValueMap
- func RequestHeadersMap(r *http.Request) util.ValueMap
- func RespondCSV(w *WriteCounter, filename string, body any) (string, error)
- func RespondDebug(w *WriteCounter, r *http.Request, as *app.State, filename string, ...) (string, error)
- func RespondDownload(filename string, ba []byte, w *WriteCounter) (string, error)
- func RespondJSON(w *WriteCounter, filename string, body any) (string, error)
- func RespondMIME(filename string, mime string, ba []byte, w *WriteCounter) (string, error)
- func RespondTOML(w *WriteCounter, filename string, body any) (string, error)
- func RespondXML(w *WriteCounter, filename string, body any) (string, error)
- func RespondYAML(w *WriteCounter, filename string, body any) (string, error)
- func ResponseHeadersMap(w http.ResponseWriter) util.ValueMap
- func URLAddQuery(u *url.URL, k string, v string)
- func WireRouter(r *mux.Router, notFound http.HandlerFunc, logger util.Logger) (http.Handler, error)
- func WriteCORS(w http.ResponseWriter)
- type Arg
- type ArgResults
- type Args
- type Location
- type Locations
- type PageState
- func (p *PageState) AddIcon(keys ...string)
- func (p *PageState) AuthString() string
- func (p *PageState) ClassDecl() string
- func (p *PageState) Clean(_ *http.Request, as *app.State) error
- func (p *PageState) Close()
- func (p *PageState) LogError(msg string, args ...any)
- func (p *PageState) SetTitleAndData(title string, data any)
- func (p *PageState) TitleString() string
- func (p *PageState) Username() string
- type WorkspaceRequest
- type WriteCounter
- func (w *WriteCounter) Count() int64
- func (w *WriteCounter) Header() http.Header
- func (w *WriteCounter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *WriteCounter) Started() time.Time
- func (w *WriteCounter) StatusCode() int
- func (w *WriteCounter) Unwrap() http.ResponseWriter
- func (w *WriteCounter) Write(buf []byte) (int, error)
- func (w *WriteCounter) WriteHeader(statusCode int)
- type XMLResponse
Constants ¶
View Source
const ( HeaderAccept = "Accept" 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 FormatJSON ¶
func FormatMarkdown ¶ added in v0.2.12
func FormatMarkdownClean ¶ added in v0.3.8
func GetContentType ¶
func IsContentTypeCSV ¶ added in v0.4.0
func IsContentTypeDebug ¶ added in v0.4.0
func IsContentTypeJSON ¶
func IsContentTypeTOML ¶ added in v0.4.4
func IsContentTypeXML ¶
func IsContentTypeYAML ¶
func ParseFormAsMaps ¶ added in v0.4.4
func PathString ¶ added in v0.4.1
func RequestCtxToMap ¶
func RespondCSV ¶ added in v0.4.0
func RespondCSV(w *WriteCounter, filename string, body any) (string, error)
func RespondDebug ¶
func RespondDownload ¶ added in v0.4.14
func RespondDownload(filename string, ba []byte, w *WriteCounter) (string, error)
func RespondJSON ¶
func RespondJSON(w *WriteCounter, filename string, body any) (string, error)
func RespondMIME ¶
func RespondTOML ¶ added in v0.4.4
func RespondTOML(w *WriteCounter, filename string, body any) (string, error)
func RespondXML ¶
func RespondXML(w *WriteCounter, filename string, body any) (string, error)
func RespondYAML ¶
func RespondYAML(w *WriteCounter, filename string, body any) (string, error)
func ResponseHeadersMap ¶ added in v0.2.20
func ResponseHeadersMap(w http.ResponseWriter) util.ValueMap
func WireRouter ¶ added in v0.4.0
func WriteCORS ¶
func WriteCORS(w http.ResponseWriter)
Types ¶
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.2.12
func (a *ArgResults) HasMissing() bool
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"` Accounts user.Accounts `json:"accounts,omitempty"` Authed bool `json:"authed,omitempty"` Admin bool `json:"admin,omitempty"` Params filter.ParamSet `json:"params,omitempty"` Icons []string `json:"icons,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"` NoScript bool `json:"noScript,omitempty"` ForceRedirect string `json:"forceRedirect,omitempty"` DefaultFormat string `json:"defaultFormat,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"` ResponseBytes int64 `json:"responseBytes,omitempty"` RequestBody []byte `json:"-"` W *WriteCounter `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.2.5
func LoadPageState(as *app.State, w *WriteCounter, r *http.Request, key string, logger util.Logger) *PageState
@contextcheck(req_has_ctx).
func (*PageState) AuthString ¶ added in v0.2.12
func (*PageState) SetTitleAndData ¶ added in v0.3.9
func (*PageState) TitleString ¶
type WorkspaceRequest ¶
type WorkspaceRequest struct { T string `json:"t"` K string `json:"k"` Req *http.Request `json:"-"` ReqBody []byte `json:"-"` Rsp http.ResponseWriter `json:"-"` PS *PageState `json:"-"` Item any `json:"item,omitempty"` Path []string `json:"path,omitempty"` Project *project.Project `json:"-"` Sources source.Sources `json:"-"` Schemata schema.Schemata `json:"-"` Context context.Context `json:"-"` //nolint:containedctx // properly closed, never directly used }
func (*WorkspaceRequest) Clone ¶
func (r *WorkspaceRequest) Clone() *WorkspaceRequest
func (*WorkspaceRequest) Route ¶
func (r *WorkspaceRequest) Route(path ...string) string
type WriteCounter ¶ added in v0.4.4
type WriteCounter struct { http.ResponseWriter // contains filtered or unexported fields }
func NewWriteCounter ¶ added in v0.4.4
func NewWriteCounter(w http.ResponseWriter) *WriteCounter
func (*WriteCounter) Count ¶ added in v0.4.4
func (w *WriteCounter) Count() int64
func (*WriteCounter) Header ¶ added in v0.4.4
func (w *WriteCounter) Header() http.Header
func (*WriteCounter) Hijack ¶ added in v0.4.4
func (w *WriteCounter) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*WriteCounter) Started ¶ added in v0.4.4
func (w *WriteCounter) Started() time.Time
func (*WriteCounter) StatusCode ¶ added in v0.4.4
func (w *WriteCounter) StatusCode() int
func (*WriteCounter) Unwrap ¶ added in v0.4.4
func (w *WriteCounter) Unwrap() http.ResponseWriter
func (*WriteCounter) WriteHeader ¶ added in v0.4.4
func (w *WriteCounter) WriteHeader(statusCode int)
type XMLResponse ¶
type XMLResponse struct {
Result any `xml:"result"`
}
Click to show internal directories.
Click to hide internal directories.