util

package
v1.777.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserTypeChatAdmin       = "chat-admin"
	UserTypeVideoNormalUser = "video-normal-user"
)
View Source
const Null = "N/A"

Variables

View Source
var (
	ErrInvalidIp = errors.New("invalid IP format")
)
View Source
var (
	MaxmindDownloadInProgress bool
)
View Source
var ReFieldWhiteList *regexp.Regexp

Functions

func AdjustTimeFromSecToMilli

func AdjustTimeFromSecToMilli(timeStr string, offsetMs int) string

func AdjustTimeWithMilli

func AdjustTimeWithMilli(timeStr string, offsetMs int) string

func AppendWebConfigCookie

func AppendWebConfigCookie(ctx *context.Context) error

func CopyFile

func CopyFile(dest string, src string)

func DecodeBase64

func DecodeBase64(s string) string

func DeleteVal

func DeleteVal(values []string, val string) []string

func DownloadFile

func DownloadFile(url string) (*bytes.Buffer, error)

func EnsureFileFolderExists

func EnsureFileFolderExists(path string)

func EnsureFolderExists

func EnsureFolderExists(path string)

func FileExist

func FileExist(path string) bool

func FilterField

func FilterField(field string) bool

func FilterQuery

func FilterQuery(urlString string, blackList []string) string

func FloatsToStrings

func FloatsToStrings(floatArray []float64) []string

func GenerateId

func GenerateId() string

func GenerateUUID

func GenerateUUID() string

func GetChatFromProvider

func GetChatFromProvider(owner, name string) string

func GetCurrentTime

func GetCurrentTime() string

func GetCurrentTimeBasedOnLastMilli

func GetCurrentTimeBasedOnLastMilli(timestamp string) string

func GetCurrentTimeEx

func GetCurrentTimeEx(timestamp string) string

func GetCurrentTimeWithMilli

func GetCurrentTimeWithMilli() string

func GetCurrentUnixTime

func GetCurrentUnixTime() int64

GetCurrentUnixTime returns the current Unix timestamp in seconds

func GetDescFromIP

func GetDescFromIP(ip string) string

GetDescFromIP returns a string description of an IP address

func GetDescFromUserAgent

func GetDescFromUserAgent(userAgent string) string

func GetFieldFromJsonString

func GetFieldFromJsonString(jsonStr string, fieldName string) (string, error)

func GetIPFromRequest

func GetIPFromRequest(req *http.Request) string

func GetIPInfo

func GetIPInfo(clientIP string) string

func GetId

func GetId(owner, name string) string

func GetIdFromOwnerAndName

func GetIdFromOwnerAndName(owner string, name string) string

func GetLocalIPAddresses

func GetLocalIPAddresses() ([]string, error)

GetLocalIPAddresses returns all non-loopback IP addresses of the local machine Returns both IPv4 and IPv6 addresses

func GetOwnerAndNameFromId3

func GetOwnerAndNameFromId3(id string) (string, string, string)

func GetOwnerAndNameFromId3New

func GetOwnerAndNameFromId3New(id string) (string, string, string)

func GetOwnerAndNameFromIdNoCheck

func GetOwnerAndNameFromIdNoCheck(id string) (string, string)

func GetOwnerAndNameFromIdWithError

func GetOwnerAndNameFromIdWithError(id string) (string, string, error)

func GetPath

func GetPath(path string) string

func GetRandomName

func GetRandomName() string

func GetRandomString

func GetRandomString(length int) string

func GetUploadCsvPath

func GetUploadCsvPath(fileId string) string

func GetUploadFilePath

func GetUploadFilePath(fileId string) string

func GetUploadXlsxPath

func GetUploadXlsxPath(fileId string) string

func HaveIntersection

func HaveIntersection(arr1 []string, arr2 []string) bool

func InSlice

func InSlice(slice []string, elem string) bool

func IndexAt

func IndexAt(s, sep string, n int) int

func Init

func Init(dataFile string) (err error)

Init defaut locator with dataFile

func InitIpDb

func InitIpDb()

InitIpDb initializes the IP database based on configuration

func InitMaxmindDb

func InitMaxmindDb() error

InitMaxmindDb initializes the MaxMind GeoIP2 databases

func InitMaxmindFiles

func InitMaxmindFiles()

InitMaxmindFiles checks if MaxMind database files exist and downloads them if needed

func InitParser

func InitParser()

func InitWithData

func InitWithData(data []byte)

Init defaut locator with data

func IsAdmin

func IsAdmin(user *casdoorsdk.User) bool

IsAdmin checks if the user is either a system admin or a chat-admin

func IsAnonymousUserByUsername

func IsAnonymousUserByUsername(username string) bool

func IsGlobalAdmin

func IsGlobalAdmin(user *casdoorsdk.User) bool

IsGlobalAdmin checks if the user is a system-level admin (IsAdmin flag only)

func IsIPAddress

func IsIPAddress(target string) bool

IsIPAddress checks if a string is a valid IP address (not a hostname)

func IsInternetIp

func IsInternetIp(ip string) bool

func IsLocalhostTarget

func IsLocalhostTarget(target string) bool

IsLocalhostTarget checks if a target is localhost or a loopback IP (127.0.0.1, ::1, etc.)

func IsStoreAdmin

func IsStoreAdmin(user *casdoorsdk.User) bool

IsStoreAdmin checks if the user is a store-level admin (chat-admin type or 教师 tag)

func IsVideoNormalUser

func IsVideoNormalUser(user *casdoorsdk.User) bool

IsVideoNormalUser checks if the user has the video-normal-user role

func JsonToStruct

func JsonToStruct(data string, v interface{}) error

func ListFiles

func ListFiles(path string) []string

func LoadCsvFile

func LoadCsvFile(path string, rows *[][]string)

func LoadFactorFileByCsv

func LoadFactorFileByCsv(path string) ([]string, [][]float64)

func LoadFactorFileByCsv2

func LoadFactorFileByCsv2(path string) ([]string, [][]float64)

func LoadFactorFileBySpace

func LoadFactorFileBySpace(path string) ([]string, [][]float64)

func MatchTargetWithMachine

func MatchTargetWithMachine(target, hostname string) (bool, error)

MatchTargetWithMachine checks if a scan target matches the current machine based on hostname or IP addresses

func MixColor

func MixColor(c1 color.RGBA, c2 color.RGBA, t float64) color.RGBA

func ParseFloat

func ParseFloat(s string) float64

func ParseInt

func ParseInt(s string) int

func ParseIntWithError

func ParseIntWithError(s string) (int, error)

func ReadBytesFromPath

func ReadBytesFromPath(path string) ([]byte, error)

func ReadStringFromPath

func ReadStringFromPath(path string) string

func RemoveExt

func RemoveExt(filename string) string

func ReplaceVal

func ReplaceVal(values []string, oldVal string, newVal string) []string

func ReturnAnyNotEmpty

func ReturnAnyNotEmpty(strs ...string) string

func SafeGoroutine

func SafeGoroutine(fn func())

func SnakeString

func SnakeString(s string) string

SnakeString transform XxYy to xx_yy

func StopOldInstance

func StopOldInstance(port int) error

func StringsToFloats

func StringsToFloats(stringArray []string) []float64

func StructToJson

func StructToJson(v interface{}) string

func StructToJsonNoIndent

func StructToJsonNoIndent(v interface{}) string

func WriteBytesToPath

func WriteBytesToPath(b []byte, path string) error

func WriteCsvFile

func WriteCsvFile(path string, rows *[][]string)

func WriteStringToPath

func WriteStringToPath(s string, path string)

Types

type LocationInfo

type LocationInfo struct {
	Country string
	Region  string
	City    string
	Isp     string
}

func Find

func Find(ipstr string) (*LocationInfo, error)

Find locationInfo by ip string It will return err when ipstr is not a valid format

func FindByUint

func FindByUint(ip uint32) *LocationInfo

Find locationInfo by uint32

func FindMaxmind

func FindMaxmind(ipstr string) (*LocationInfo, error)

FindMaxmind looks up IP information using MaxMind GeoIP2

func GetInfoFromIP

func GetInfoFromIP(ip string) (*LocationInfo, error)

type Locator

type Locator struct {
	// contains filtered or unexported fields
}

func NewLocator

func NewLocator(dataFile string) (loc *Locator, err error)

New locator with dataFile

func NewLocatorWithData

func NewLocatorWithData(data []byte) (loc *Locator)

New locator with data

func (*Locator) Find

func (loc *Locator) Find(ipstr string) (info *LocationInfo, err error)

Find locationInfo by ip string It will return err when ipstr is not a valid format

func (*Locator) FindByUint

func (loc *Locator) FindByUint(ip uint32) (info *LocationInfo)

Find locationInfo by uint32

type SystemInfo

type SystemInfo struct {
	CpuUsage     []float64 `json:"cpuUsage"`
	MemoryUsed   uint64    `json:"memoryUsed"`
	MemoryTotal  uint64    `json:"memoryTotal"`
	DiskUsed     uint64    `json:"diskUsed"`
	DiskTotal    uint64    `json:"diskTotal"`
	NetworkSent  uint64    `json:"networkSent"`
	NetworkRecv  uint64    `json:"networkRecv"`
	NetworkTotal uint64    `json:"networkTotal"`
}

func GetSystemInfo

func GetSystemInfo() (*SystemInfo, error)

type VersionInfo

type VersionInfo struct {
	Version      string `json:"version"`
	CommitId     string `json:"commitId"`
	CommitOffset int    `json:"commitOffset"`
}

func GetVersionInfo

func GetVersionInfo() (*VersionInfo, error)

GetVersionInfo get git current commit and repo release version

func GetVersionInfoFromFile

func GetVersionInfoFromFile() (*VersionInfo, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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