Documentation ¶
Overview ¶
Package clean provides validation, sanitation, and normalization of input values.
Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.
This program is free software: you can redistribute it and/or modify it under Version 3 of the GNU Affero General Public License (the "AGPL"): <https://docs.photoprism.app/license/agpl> This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. The AGPL is supplemented by our Trademark and Brand Guidelines, which describe how our Brand Assets may be used: <https://www.photoprism.app/trademark>
Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.
Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>
Index ¶
- Constants
- Variables
- func ASCII(s string) string
- func Altitude(a float64) int
- func Attr(s string) string
- func Auth(s string) string
- func Clip(s string, maxLen int) string
- func Codec(s string) string
- func Color(s string) string
- func Duration(s string) string
- func Email(s string) string
- func Error(err error) string
- func FileName(s string) string
- func GPSBounds(bounds string) (latN, lngE, latS, lngW float32, err error)
- func GPSLatRange(lat float64, km float64) (latN, latS float32, err error)
- func GPSLngRange(lng float64, km float64) (lngE, lngW float32, err error)
- func Handle(s string) string
- func Header(s string) string
- func Hex(s string) string
- func ID(s string) string
- func IP(s, defaultIp string) string
- func IdUint(s string) uint
- func Log(s string) string
- func LogLower(s string) string
- func LogQuote(s string) string
- func Name(name string) string
- func NameCapitalized(name string) string
- func Numeric(s string) string
- func Orientation(val int) int
- func Passcode(s string) string
- func Password(s string) string
- func Path(s string) string
- func Role(s string) string
- func Scope(s string) string
- func SearchQuery(s string) string
- func SearchString(s string) string
- func ShareToken(s string) string
- func ShortType(s string) string
- func ShortTypeLower(s string) string
- func ShortTypeLowerUnderscore(s string) string
- func SqlSpecial(b byte) (special bool, omit bool)
- func SqlString(s string) string
- func State(s, countryCode string) string
- func Token(s string) string
- func Type(s string) string
- func TypeLower(s string) string
- func TypeLowerUnderscore(s string) string
- func UID(s string) string
- func Unicode(s string) string
- func Uri(s string) string
- func UrlToken(s string) string
- func UserPath(dir string) string
- func Username(s string) string
Constants ¶
const ( ClipShortType = 8 ClipIPv6 = 39 ClipType = 64 )
const ( EnOr = "or" EnAnd = "and" EnWith = "with" EnIn = "in" EnAt = "at" Empty = "" Space = " " Or = "|" And = "&" Plus = "+" SpacedPlus = Space + Plus + Space )
const MaxLength = 4096
Variables ¶
var EmailRegexp = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
var IpRegExp = regexp.MustCompile(`[^a-zA-Z0-9:.]`)
IpRegExp matches characters allowed in IPv4 or IPv6 network addresses.
Functions ¶
func Altitude ¶
Altitude returns the altitude within a maximum range as an integer, or 0 if it is invalid.
func Auth ¶
Auth returns the sanitized authentication identifier trimmed to a maximum length of 255 characters.
func Clip ¶
Clip shortens a string to the given number of characters, and removes all leading and trailing white space.
func Color ¶
Color sanitizes HTML color codes and returns them in lowercase if they are valid, or an empty string otherwise.
func GPSBounds ¶
GPSBounds parses the GPS bounds (Lat N, Lng E, Lat S, Lng W) and returns the coordinates if any.
func GPSLatRange ¶
GPSLatRange returns a range based on the specified latitude and distance in km, or an error otherwise.
func GPSLngRange ¶
GPSLngRange returns a range based on the specified longitude and distance in km, or an error otherwise.
func ID ¶
ID sanitizes identifier tokens, for example, a session ID, a UUID, or some other string ID.
func IP ¶
IP returns the sanitized and normalized network address if it is valid, or the default otherwise.
func IdUint ¶
IdUint converts the string converted to an unsigned integer and 0 if the string is invalid.
func NameCapitalized ¶
NameCapitalized sanitizes and capitalizes a name.
func Orientation ¶
Orientation returns the Exif orientation value within a valid range or 0 if it is invalid.
func Passcode ¶
Passcode sanitizes a passcode and returns it in lowercase with all whitespace removed.
func Password ¶
Password returns the password string with all leading and trailing white space removed.
func SearchQuery ¶
SearchQuery replaces search operator with default symbols.
func SearchString ¶
SearchString replaces search operator with default symbols.
func ShareToken ¶
ShareToken returns the sanitized link share token with a length of up to 160 characters.
func ShortType ¶
ShortType omits invalid runes, ensures a maximum length of 8 characters, and returns the result.
func ShortTypeLower ¶
ShortTypeLower converts a short type string to lowercase, omits invalid runes, and shortens it if needed.
func ShortTypeLowerUnderscore ¶
ShortTypeLowerUnderscore converts a string to a short lowercase type string and replaces spaces with underscores.
func SqlSpecial ¶
SqlSpecial checks if the byte must be escaped/omitted in SQL.
func Type ¶
Type omits invalid runes, ensures a maximum length of 32 characters, and returns the result.
func TypeLower ¶
TypeLower converts a type string to lowercase, omits invalid runes, and shortens it if needed.
func TypeLowerUnderscore ¶
TypeLowerUnderscore converts a string to a lowercase type string and replaces spaces with underscores.
Types ¶
This section is empty.