Documentation
¶
Index ¶
- Constants
- Variables
- func Add(a, b int) int
- func CountURLs(text string) int
- func CurrentYear() int
- func FirstNChars(s string, n int) string
- func FormatDate(t time.Time) string
- func FormatDateCn(t time.Time) string
- func FormatDateEn(t time.Time) string
- func FormatPrice(price float64) string
- func GenDescription(html string) string
- func GenerateToken(resource string, ttl time.Duration) (string, error)
- func GetDomain(debug bool) string
- func HasRussianChars(text string) bool
- func IsValidEmail(email string) bool
- func MarkdownToHTML(markdown string) template.HTML
- func SafeHTML(s string) template.HTML
- func SafeJS(s string) template.JS
- func SendMail(to, cc, subject, body string, config SMTPConfig) error
- func SetSecret(secret []byte)
- func Slugify(value string) string
- func Split(s, sep string) []string
- func Sub(a, b int) int
- func TotalWords(s string) int
- func UnescapeHTML(s string) template.HTML
- func Until(n int) []int
- type AntdCurrentUserResult
- type AntdLoginResult
- type AntdResult
- type CommonResponse
- type NullTime
- type SMTPConfig
- type TokenPayload
Constants ¶
const Version = "v1.0.4"
Variables ¶
var ( // ErrInvalidToken token format invalid ErrInvalidToken = errors.New("invalid token format") // ErrSignatureMismatch token signature verification failed ErrSignatureMismatch = errors.New("token signature mismatch") // ErrExpired token expired ErrExpired = errors.New("token expired") )
var TemplateFuncMap = template.FuncMap{ "sub": Sub, "add": Add, "until": Until, "split": Split, "formatPrice": FormatPrice, "SafeHTML": SafeHTML, "SafeJS": SafeJS, "FormatDate": FormatDate, "FormatDateEn": FormatDateEn, "FormatDateCn": FormatDateCn, "GenDescription": GenDescription, "CurrentYear": CurrentYear, }
Functions ¶
func FirstNChars ¶
FirstNChars 字符串的前 N 个字符 fmt.Println(firstN2("世界 Hello", 1)) // 世
func FormatDateCn ¶ added in v1.0.2
Format Datetime As Chinese Locale, E.g: 2006年01月02日
func FormatDateEn ¶
Format Datetime As English Locale, E.g: January 02, 2006
func GenerateToken ¶
GenerateToken creates a signed token for the given resource that expires after ttl.
func IsValidEmail ¶ added in v1.0.1
email address validation regex
func MarkdownToHTML ¶
MarkdownToHTML converts markdown to html
func SendMail ¶
func SendMail(to, cc, subject, body string, config SMTPConfig) error
SendMail 发送邮件 配置参数示例:
{
"Host": "smtp.163.com",
"Port": 465,
"User": "user@163.com",
"Pass": "password",
"UserName": "发件人名称"
}
func SetSecret ¶
func SetSecret(secret []byte)
SetSecret sets the secret used to sign/verify tokens. Call this during application startup if you want a stable secret.
Types ¶
type AntdCurrentUserResult ¶
type AntdCurrentUserResult struct {
Name string `json:"name"`
Access string `json:"access" enums:"admin,agent"`
Avatar string `json:"avatar"`
}
AntdCurrentUserResult .
type AntdLoginResult ¶
type AntdLoginResult struct {
Status string `json:"status" enums:"ok,not ok"`
Token string `json:"token"`
}
AntdLoginResult .
type AntdResult ¶
type AntdResult struct {
Success bool `json:"success"`
Data interface{} `json:"data"`
Total int64 `json:"total" example:"100"`
}
AntdResult Antd Pro table list api
type CommonResponse ¶
type SMTPConfig ¶
type TokenPayload ¶
type TokenPayload struct {
Resource string `json:"res"`
Iat int64 `json:"iat"`
Exp int64 `json:"exp"`
Nonce string `json:"nonce"`
}
TokenPayload is the JSON payload embedded in the token.
func ParseToken ¶
func ParseToken(token string) (TokenPayload, error)
ParseToken verifies the token signature and returns the decoded payload. It does NOT check expiration; use ValidateToken to also enforce expiry.
func ValidateToken ¶
func ValidateToken(token string) (TokenPayload, error)
ValidateToken parses the token, verifies signature and expiration. Returns the payload if valid.