Documentation ¶
Index ¶
- Constants
- Variables
- func AppendLine(path string, content string) errors.WTError
- func ApplyImageStyle(imageUrl, styleName string) string
- func CheckIPInList(ip string, ipList []string, canAll bool, canIP bool, canCIDR bool) bool
- func Close(f Closer)
- func Contains(search interface{}, target interface{}) bool
- func ContainsIgnoreCase(search string, target []string) bool
- func Decode62(str string) int64
- func DecodeFromBase62(encoded string) []byte
- func Encode62(number int64) string
- func EncodeBase62(num uint64) string
- func EncodeToBase62(data []byte) string
- func FormatJson(obj interface{}) (str string, err errors.WTError)
- func GenerateRandomInt(min, max int) int64
- func GenerateRandomText(length int) string
- func GenerateUniqueNumber(length int) string
- func GetDay(time time.Time) int
- func GetHtmlSummary(text string) string
- func GetMediaType(data []byte) string
- func GetSummary(content string) (summary string)
- func GetTargetIP(r *http.Request) (ip string)
- func GetUserName(defaultName string, username sql.NullString, nickname sql.NullString) string
- func GetUserNameByPhone(phone string, username sql.NullString, nickname sql.NullString) string
- func HashSHA1(s string) string
- func HashSHA256(str string) string
- func HashSHA256WithBase62(str string) string
- func InList[T string | int64](lst []T, element T) bool
- func IndexOf(userIds []int64, userId int64) int
- func IsAcceptType(fileType string) bool
- func IsAudio(fileType string) bool
- func IsEmpty(a interface{}) bool
- func IsIPInCIDR(ip string, cidr string) bool
- func IsImage(fileType string) bool
- func IsJsonString(data string) bool
- func IsLocalIP(ip string) bool
- func IsNetClose(err error) bool
- func IsPdf(fileType string) bool
- func IsProd() bool
- func IsValidateEmail(email string) (err errors.WTError)
- func IsValidatePassword(password, rePassword string) errors.WTError
- func IsValidateUrl(url string) errors.WTError
- func IsValidateUsername(username string) errors.WTError
- func IsVideo(fileType string) bool
- func JoinIntToString(lst []int64, seq string, removeDuplicates bool) string
- func JoinStringToString(lst []string, seq string, removeDuplicates bool) string
- func JsonMarshal(v interface{}) ([]byte, errors.WTError)
- func JsonUnmarshal(data []byte, v interface{}) errors.WTError
- func JustAudio(fileType string) bool
- func JustImage(fileType string) bool
- func JustVideo(fileType string) bool
- func ListConvert[T1, T2 string | int64](lst []T1, m map[T1]T2) []T2
- func ListConvertMust[T1, T2 string | int64](lst []T1, m map[T1]T2) ([]T2, errors.WTError)
- func MD5(str string) string
- func MD5Bytes(data []byte) string
- func MapToStruct(obj interface{}, data map[string]interface{}) errors.WTError
- func MurmurHashWithBase62(s string) string
- func MustNotError(err error)
- func NowTimestamp() int64
- func NowUnix() int64
- func OnceFunc(f func()) func()
- func ParseJson(str string, t interface{}) errors.WTError
- func ParseTagsToArray(tags string) []string
- func PathExists(path string) (bool, errors.WTError)
- func ReadRsaPrivateKey(c []byte) (*rsa.PrivateKey, errors.WTError)
- func ReadRsaPubKeyFromCert(c []byte) (*rsa.PublicKey, errors.WTError)
- func ReadRsaPublicKey(c []byte) (*rsa.PublicKey, errors.WTError)
- func Recover(logger Logger, err *errors.WTError, msg string)
- func RemoveDuplicates[T string | int64](lst []T) []T
- func RemoveTrailingNil[T any](lst []T, isZero func(T) bool) []T
- func SignRsaHash256Sign(data string, privateKey *rsa.PrivateKey) ([]byte, errors.WTError)
- func SplitStringToInt(lst string, seq string) []int64
- func SqlNullString(value string) sql.NullString
- func StringIn(dst string, lst []string) bool
- func StructFields(s interface{}) []reflect.StructField
- func StructName(s interface{}) string
- func StructToMap(obj interface{}, excludes ...string) map[string]interface{}
- func StructTypeOf(s interface{}) reflect.Type
- func TimeFormat(time time.Time, layout string) string
- func TimeFromTimestamp(timestamp int64) time.Time
- func TimeFromUnix(unix int64) time.Time
- func TimeParse(timeStr, layout string) (time.Time, errors.WTError)
- func TimeSincePro(then time.Time) string
- func Timestamp(t time.Time) int64
- func TruncateString(s string, n int64) string
- func VerifyRsaHash256Sign(data string, signature []byte, publicKey *rsa.PublicKey) errors.WTError
- func WithTimeAsStartOfDay(t time.Time) time.Time
- func WriteString(path string, content string, append bool) errors.WTError
- type BaseFunc
- type Closer
- type CodeError
- type Logger
- type UrlBuilder
- func (builder *UrlBuilder) AddQueries(queries map[string]string) *UrlBuilder
- func (builder *UrlBuilder) AddQuery(name, value string) *UrlBuilder
- func (builder *UrlBuilder) Build() *url.URL
- func (builder *UrlBuilder) BuildStr() string
- func (builder *UrlBuilder) GetQuery() url.Values
- func (builder *UrlBuilder) GetURL() *url.URL
Constants ¶
View Source
const ( FMT_DATE_TIME = "2006-01-02 15:04:05" FMT_DATE = "2006-01-02" FMT_TIME = "15:04:05" FMT_DATE_TIME_CN = "2006年01月02日 15时04分05秒" FMT_DATE_CN = "2006年01月02日" FMT_TIME_CN = "15时04分05秒" )
View Source
const ( Minute = 60 Hour = 60 * Minute Day = 24 * Hour Week = 7 * Day Month = 30 * Day Year = 12 * Month )
Seconds-based time units
View Source
const CODE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
View Source
const CodeLength = 62
Variables ¶
View Source
var ( ErrorTopicNotFound = NewError(-1, "话题不存在") ErrorArticleNotFound = NewError(-2, "文章不存在") ErrorTagNotFound = NewError(-3, "标签不存在") ErrorPermissionDenied = NewError(-100, "Permission denied.") ErrorNotLogin = NewError(-200, "请先登录") )
View Source
var CodeMap = map[string]int64{"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "a": 10,
"b": 11, "redis": 12, "d": 13, "e": 14, "f": 15, "g": 16, "h": 17, "i": 18, "j": 19, "k": 20, "l": 21, "m": 22,
"n": 23, "o": 24, "p": 25, "q": 26, "r": 27, "s": 28, "t": 29, "u": 30, "v": 31, "w": 32, "x": 33, "y": 34,
"z": 35, "A": 36, "B": 37, "C": 38, "D": 39, "E": 40, "F": 41, "G": 42, "H": 43, "I": 44, "J": 45, "K": 46,
"L": 47, "M": 48, "N": 49, "O": 50, "P": 51, "Q": 52, "R": 53, "S": 54, "T": 55, "U": 56, "V": 57, "W": 58,
"X": 59, "Y": 60, "Z": 61}
View Source
var MediaTypeSuffixMap = map[string]string{
"image/png": "png",
"image/jpeg": "jpeg",
"image/bmp": "bmp",
"video/avi": "avi",
"video/mp4": "mp4",
"audio/mpeg": "mp3",
"audio/wave": "wav",
"application/pdf": "pdf",
}
Functions ¶
func CheckIPInList ¶
func ContainsIgnoreCase ¶
func DecodeFromBase62 ¶
func EncodeBase62 ¶
func EncodeToBase62 ¶
func FormatJson ¶
func GenerateRandomInt ¶
func GenerateRandomText ¶
func GenerateUniqueNumber ¶
func GetMediaType ¶
func GetSummary ¶
func GetTargetIP ¶
func GetUserName ¶
func GetUserName(defaultName string, username sql.NullString, nickname sql.NullString) string
func GetUserNameByPhone ¶
func GetUserNameByPhone(phone string, username sql.NullString, nickname sql.NullString) string
func HashSHA256 ¶
func HashSHA256WithBase62 ¶
func IsAcceptType ¶
func IsIPInCIDR ¶
func IsJsonString ¶
func IsNetClose ¶
func IsValidatePassword ¶
是否是合法的密码
func IsValidateUsername ¶
验证用户名合法性,用户名必须由5-12位(数字、字母、_、-)组成,且必须以字母开头。
func JoinStringToString ¶
func JsonMarshal ¶
func JsonUnmarshal ¶
func ListConvert ¶
func ListConvertMust ¶
func MapToStruct ¶
func MustNotError ¶
func MustNotError(err error)
func ReadRsaPrivateKey ¶
func ReadRsaPrivateKey(c []byte) (*rsa.PrivateKey, errors.WTError)
func RemoveDuplicates ¶
func RemoveTrailingNil ¶
func SignRsaHash256Sign ¶
func SplitStringToInt ¶
func SqlNullString ¶
func SqlNullString(value string) sql.NullString
func StructToMap ¶
func StructTypeOf ¶
func TimeSincePro ¶
TimeSincePro calculates the time interval and generate full user-friendly string.
func TruncateString ¶
func VerifyRsaHash256Sign ¶
Types ¶
type UrlBuilder ¶
type UrlBuilder struct {
// contains filtered or unexported fields
}
func ParseUrl ¶
func ParseUrl(rawUrl string) *UrlBuilder
func (*UrlBuilder) AddQueries ¶
func (builder *UrlBuilder) AddQueries(queries map[string]string) *UrlBuilder
func (*UrlBuilder) AddQuery ¶
func (builder *UrlBuilder) AddQuery(name, value string) *UrlBuilder
func (*UrlBuilder) Build ¶
func (builder *UrlBuilder) Build() *url.URL
func (*UrlBuilder) BuildStr ¶
func (builder *UrlBuilder) BuildStr() string
func (*UrlBuilder) GetQuery ¶
func (builder *UrlBuilder) GetQuery() url.Values
func (*UrlBuilder) GetURL ¶
func (builder *UrlBuilder) GetURL() *url.URL
Source Files ¶
Click to show internal directories.
Click to hide internal directories.