util

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeautifulName

func BeautifulName(uglyName string) string

BeautifulName makes the ugly name beautiful by replacing _ with spaces and using title case.

func CanonicalName

func CanonicalName(name string) string

CanonicalName makes sure the `name` is canonical. A name is canonical if it is lowercase and all spaces are replaced with underscores.

func HTTP200Page

func HTTP200Page(w http.ResponseWriter, page string)

HTTP200Page wraps some frequently used things for successful 200 responses. TODO: demolish

func HTTP404Page

func HTTP404Page(w http.ResponseWriter, page string)

HTTP404Page writes a 404 error in the status, needed when no content is found on the page. TODO: demolish

func HyphaNameFromRq added in v1.2.0

func HyphaNameFromRq(rq *http.Request, actions ...string) string

HyphaNameFromRq extracts hypha name from http request. You have to also pass the action which is embedded in the url or several actions. For url /hypha/hypha, the action would be "hypha".

func IsProfileName added in v1.8.0

func IsProfileName(hyphaName string) bool

IsProfileName if the given hypha name is a profile name. It takes configuration into consideration.

With default configuration, u/ is the prefix such names have. For example, u/wikimind matches. Note that u/wikimind/sub does not.

func IsRevHash added in v1.14.0

func IsRevHash(revHash string) bool

IsRevHash checks if the revision hash is valid.

func PrepareRq added in v1.2.0

func PrepareRq(rq *http.Request)

PrepareRq strips the trailing / in rq.URL.Path. In the future it might do more stuff for making all request structs uniform.

func RandomString

func RandomString(n int) (string, error)

RandomString generates a random string of the given length. It is cryptographically secure to some extent.

func ShorterPath

func ShorterPath(path string) string

ShorterPath is used by handlerList to display shorter path to the files. It simply strips the hyphae directory name.

Types

type FormData added in v1.3.0

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

FormData is a convenient struct for passing user input and errors to HTML forms and showing to the user.

func FormDataFromRequest added in v1.3.0

func FormDataFromRequest(r *http.Request, keys []string) FormData

FormDataFromRequest extracts a form data from request, using a set of keys.

func NewFormData added in v1.3.0

func NewFormData() FormData

NewFormData constructs empty form data instance.

func (FormData) Error added in v1.3.0

func (f FormData) Error() string

Error returns an error text or empty string, if there are no errors in form data.

func (FormData) Get added in v1.3.0

func (f FormData) Get(key string) string

Get accesses form data with a key

func (FormData) HasError added in v1.3.0

func (f FormData) HasError() bool

HasError is true if there is indeed an error.

func (FormData) Put added in v1.3.0

func (f FormData) Put(key, value string)

Put writes a form value for provided key

func (FormData) WithError added in v1.3.0

func (f FormData) WithError(err error) FormData

WithError puts an error into form data and returns itself.

Jump to

Keyboard shortcuts

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