FILE / ScuroNeko/Laniakea

utils.go

Исходный файл и его история в репозитории.
FILE d78526242bc7aa184ce5e030b95d8afe2d1243c4
Files
Laniakea/utils.go
T
ScuroNeko d78526242b
Golang lint / lint (push) Failing after 1m37s
(new): support Bot API 10.3
(fix): finalize v2 contracts
(tests): cover v2 migration
(doc): prepare release guidance
2026-09-08 23:21:38 +03:00

43 lines
1005 B
Go

package laniakea
import (
"crypto/rand"
"encoding/base64"
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
)
// Ptr returns a pointer to v.
//
//go:fix inline
func Ptr[T any](v T) *T { return new(v) }
// Val returns dereferenced pointer value or def when p is nil.
func Val[T any](p *T, def T) T {
if p != nil {
return *p
}
return def
}
const (
// VersionString re-exports the module version string.
VersionString = utils.VersionString
// VersionMajor re-exports the module major version.
VersionMajor = utils.VersionMajor
// VersionMinor re-exports the module minor version.
VersionMinor = utils.VersionMinor
// VersionPatch re-exports the module patch version.
VersionPatch = utils.VersionPatch
// VersionBeta re-exports the module prerelease counter.
VersionBeta = utils.VersionBeta
)
func generateToken(b int) (string, error) {
bytes := make([]byte, b)
if _, err := rand.Read(bytes); err != nil {
return "", err
}
return base64.RawURLEncoding.EncodeToString(bytes), nil
}