utils

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 24 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ColorPalette = []string{
	"#ffc7c7",
	"#fff1c7",
	"#e3ffc7",
	"#c7ffd5",
	"#c7ffff",
	"#c7d5ff",
	"#e3c7ff",
	"#ffc7f1",
	"#ffa8a8",
	"#ffe699",
	"#cfff9e",
	"#99ffb3",
	"#a3ffff",
	"#99b3ff",
	"#cc99ff",
	"#ff99e5",
	"#e7b1b1",
	"#e9dcAf",
	"#cde9af",
	"#bfedcc",
	"#b1e7e7",
	"#c3cdee",
	"#d2b8ea",
	"#eec3e6",
	"#e9cece",
	"#e7e0ca",
	"#d3e5c7",
	"#bce1c5",
	"#c1e2e2",
	"#c1c9e2",
	"#cfc1e2",
	"#e0bdd9",
	"#baded3",
	"#a0f8eb",
	"#b1e7e0",
	"#c3c8e4",
	"#cec5e2",
	"#b1d5e7",
	"#cda8f0",
	"#f0f0a8",
	"#f2f2a6",
	"#f5a8eb",
	"#c5f9a9",
	"#ececbb",
	"#e7c4bc",
	"#daf0b2",
	"#b0a0fd",
	"#bce2e7",
	"#cce2bb",
	"#ec9afe",
	"#edabbd",
	"#aeaeea",
	"#c4e7b1",
	"#d722bb",
	"#f3a5e7",
	"#ffa8a8",
	"#d8c0c5",
	"#eaaedd",
	"#adc6eb",
	"#bedad1",
	"#dee9af",
	"#e9afc2",
	"#f8d2a0",
	"#b3b3e6",
}
View Source
var RandomVersionString = versionString()

RandomVersionString is the cache-busting token of the asset URLs ("pad.js?v=..."). It is the same for every instance running the same build (etherpad-lite #7213: a random value per start made every restart and every instance behind a load balancer bust the browsers' caches) and can be set with ETHERPAD_VERSION_STRING.

Functions

func CheckValidRev

func CheckValidRev(rev string) (*int, error)

func CleanProxyPath added in v0.7.0

func CleanProxyPath(raw string) string

CleanProxyPath makes a header value safe to put in front of a path in HTML, JavaScript, CSS and Location headers: only [A-Za-z0-9-_./] stay, a leading // becomes / (no protocol-relative URL), a missing leading / is added, a value with a ".." segment is dropped and trailing slashes go. The result is "" or starts with exactly one "/" and does not end with one (etherpad-lite's sanitizeProxyPath, which keeps "/" and a trailing slash).

func CountLines

func CountLines(s string, r rune) int

func CountLinesRunes added in v0.0.2

func CountLinesRunes(s []rune, r rune) int

func EndsWithNewLine added in v0.0.2

func EndsWithNewLine(s []rune) bool

func ExistsSync

func ExistsSync(path string) bool

func GenerateAuthorToken added in v0.6.8

func GenerateAuthorToken() string

GenerateAuthorToken returns a fresh author token ("t." + 20 random characters), matching padutils.generateAuthorToken in etherpad-lite.

func GetDB

func GetDB(retrievedSettings settings.Settings, setupLogger *zap.SugaredLogger) (db.DataStore, error)

func IsDevModeEnabled added in v0.0.3

func IsDevModeEnabled() bool

func IsUpdateAvailable added in v0.0.5

func IsUpdateAvailable(current, latest string) bool

IsUpdateAvailable returns true if the latest version is strictly newer than the current version. It handles semantic versions and treats non-semver current versions (like commit hashes) as development builds that are considered up-to-date.

func IsValidAuthorToken

func IsValidAuthorToken(token string) bool

func LoadPluginTranslations added in v0.0.4

func LoadPluginTranslations(language string, uiAssets embed.FS, pluginName string) (map[string]string, error)

func LoadTranslations added in v0.0.2

func LoadTranslations(language string, uiAssets embed.FS, hooks *hooks.Hook) (map[string]string, error)

func NumToString

func NumToString(num int) string

func PadParam added in v0.7.0

func PadParam(c fiber.Ctx) string

PadParam is the :pad route parameter as a pad name: the router leaves some escapes in it ("100%25" for 100%), so it is unescaped once, as GuardPadURL does; a value that is not valid escaping stays as it is.

func ParseNum

func ParseNum(num string) (int, error)

func ProxyPath added in v0.7.0

func ProxyPath(header func(name string) string, trustProxy bool) string

ProxyPath is the path prefix of the request: the first proxy path header that is honoured and not empty once cleaned, or "".

func ProxyPathHeaders added in v0.7.0

func ProxyPathHeaders(trustProxy bool) []string

ProxyPathHeaders are the headers ProxyPath reads, for a Vary header.

func RandomString

func RandomString(length int) string

RandomString returns length characters from [A-Za-z0-9], drawn from crypto/rand. Its output is used for secrets (author tokens, session IDs, read-only pad IDs), so it must not come from math/rand (cf. etherpad-lite's crypto.randomBytes-based randomString).

func RequestProxyPath added in v0.7.0

func RequestProxyPath(c fiber.Ctx, trustProxy bool) string

RequestProxyPath is the path prefix of a page request (see ProxyPath). Pages that put it into their HTML vary on the headers it reads, so a shared cache in front of Etherpad cannot hand one client's prefix to another; with a prefix the answer is not stored at all.

func RuneByteOffset added in v0.7.0

func RuneByteOffset(s string, n int) int

RuneByteOffset returns the byte offset of the n-th rune in s, or len(s) if s has fewer runes.

func RuneCount added in v0.0.2

func RuneCount(s string) int

RuneCount returns the same as utf8.RuneCountInString but checks eight ASCII bytes at a time, which is several times faster on mostly ASCII pad texts.

func RuneIndex added in v0.0.2

func RuneIndex(s, sep string) int

func RuneIndexFromRegex added in v0.0.2

func RuneIndexFromRegex(re *regexp.Regexp, s string) (int, int)

func RuneLastIndex added in v0.0.2

func RuneLastIndex(s, sep string) int

func RuneSlice added in v0.0.2

func RuneSlice(s string, start, end int) string

RuneSlice returns the runes [start, end) of s. It works on byte offsets and returns a substring of s, so it does not allocate.

func SetupLogger added in v0.0.2

func SetupLogger() *zap.SugaredLogger

func Splice

func Splice(slice []string, start, deleteCount int, items ...string) []string

Types

This section is empty.

Jump to

Keyboard shortcuts

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