Documentation
¶
Index ¶
- Constants
- Variables
- func AdjustTimeFromSecToMilli(timeStr string, offsetMs int) string
- func AdjustTimeWithMilli(timeStr string, offsetMs int) string
- func AppendWebConfigCookie(ctx *context.Context) error
- func CopyFile(dest string, src string)
- func DecodeBase64(s string) string
- func DeleteVal(values []string, val string) []string
- func DownloadFile(url string) (*bytes.Buffer, error)
- func EnsureFileFolderExists(path string)
- func EnsureFolderExists(path string)
- func FileExist(path string) bool
- func FilterField(field string) bool
- func FilterQuery(urlString string, blackList []string) string
- func FloatsToStrings(floatArray []float64) []string
- func GenerateId() string
- func GenerateUUID() string
- func GetChatFromProvider(owner, name string) string
- func GetCurrentTime() string
- func GetCurrentTimeBasedOnLastMilli(timestamp string) string
- func GetCurrentTimeEx(timestamp string) string
- func GetCurrentTimeWithMilli() string
- func GetCurrentUnixTime() int64
- func GetDescFromIP(ip string) string
- func GetDescFromUserAgent(userAgent string) string
- func GetFieldFromJsonString(jsonStr string, fieldName string) (string, error)
- func GetIPFromRequest(req *http.Request) string
- func GetIPInfo(clientIP string) string
- func GetId(owner, name string) string
- func GetIdFromOwnerAndName(owner string, name string) string
- func GetLocalIPAddresses() ([]string, error)
- func GetOwnerAndNameFromId3(id string) (string, string, string)
- func GetOwnerAndNameFromId3New(id string) (string, string, string)
- func GetOwnerAndNameFromIdNoCheck(id string) (string, string)
- func GetOwnerAndNameFromIdWithError(id string) (string, string, error)
- func GetPath(path string) string
- func GetRandomName() string
- func GetRandomString(length int) string
- func GetUploadCsvPath(fileId string) string
- func GetUploadFilePath(fileId string) string
- func GetUploadXlsxPath(fileId string) string
- func HaveIntersection(arr1 []string, arr2 []string) bool
- func InSlice(slice []string, elem string) bool
- func IndexAt(s, sep string, n int) int
- func Init(dataFile string) (err error)
- func InitIpDb()
- func InitMaxmindDb() error
- func InitMaxmindFiles()
- func InitParser()
- func InitWithData(data []byte)
- func IsAdmin(user *casdoorsdk.User) bool
- func IsAnonymousUserByUsername(username string) bool
- func IsGlobalAdmin(user *casdoorsdk.User) bool
- func IsIPAddress(target string) bool
- func IsInternetIp(ip string) bool
- func IsLocalhostTarget(target string) bool
- func IsStoreAdmin(user *casdoorsdk.User) bool
- func IsVideoNormalUser(user *casdoorsdk.User) bool
- func JsonToStruct(data string, v interface{}) error
- func ListFiles(path string) []string
- func LoadCsvFile(path string, rows *[][]string)
- func LoadFactorFileByCsv(path string) ([]string, [][]float64)
- func LoadFactorFileByCsv2(path string) ([]string, [][]float64)
- func LoadFactorFileBySpace(path string) ([]string, [][]float64)
- func MatchTargetWithMachine(target, hostname string) (bool, error)
- func MixColor(c1 color.RGBA, c2 color.RGBA, t float64) color.RGBA
- func ParseFloat(s string) float64
- func ParseInt(s string) int
- func ParseIntWithError(s string) (int, error)
- func ReadBytesFromPath(path string) ([]byte, error)
- func ReadStringFromPath(path string) string
- func RemoveExt(filename string) string
- func ReplaceVal(values []string, oldVal string, newVal string) []string
- func ReturnAnyNotEmpty(strs ...string) string
- func SafeGoroutine(fn func())
- func SnakeString(s string) string
- func StopOldInstance(port int) error
- func StringsToFloats(stringArray []string) []float64
- func StructToJson(v interface{}) string
- func StructToJsonNoIndent(v interface{}) string
- func WriteBytesToPath(b []byte, path string) error
- func WriteCsvFile(path string, rows *[][]string)
- func WriteStringToPath(s string, path string)
- type LocationInfo
- type Locator
- type SystemInfo
- type VersionInfo
Constants ¶
const ( UserTypeChatAdmin = "chat-admin" UserTypeVideoNormalUser = "video-normal-user" )
const Null = "N/A"
Variables ¶
var (
ErrInvalidIp = errors.New("invalid IP format")
)
var (
MaxmindDownloadInProgress bool
)
var Parser *uaparser.Parser
var ReFieldWhiteList *regexp.Regexp
Functions ¶
func AdjustTimeWithMilli ¶
func AppendWebConfigCookie ¶
func DecodeBase64 ¶
func EnsureFileFolderExists ¶
func EnsureFileFolderExists(path string)
func EnsureFolderExists ¶
func EnsureFolderExists(path string)
func FilterField ¶
func FilterQuery ¶
func FloatsToStrings ¶
func GenerateId ¶
func GenerateId() string
func GenerateUUID ¶
func GenerateUUID() string
func GetChatFromProvider ¶
func GetCurrentTime ¶
func GetCurrentTime() string
func GetCurrentTimeEx ¶
func GetCurrentTimeWithMilli ¶
func GetCurrentTimeWithMilli() string
func GetCurrentUnixTime ¶
func GetCurrentUnixTime() int64
GetCurrentUnixTime returns the current Unix timestamp in seconds
func GetDescFromIP ¶
GetDescFromIP returns a string description of an IP address
func GetDescFromUserAgent ¶
func GetFieldFromJsonString ¶
func GetIPFromRequest ¶
func GetIdFromOwnerAndName ¶
func GetLocalIPAddresses ¶
GetLocalIPAddresses returns all non-loopback IP addresses of the local machine Returns both IPv4 and IPv6 addresses
func GetRandomName ¶
func GetRandomName() string
func GetRandomString ¶
func GetUploadCsvPath ¶
func GetUploadFilePath ¶
func GetUploadXlsxPath ¶
func HaveIntersection ¶
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 IsAdmin ¶
func IsAdmin(user *casdoorsdk.User) bool
IsAdmin checks if the user is either a system admin or a chat-admin
func IsGlobalAdmin ¶
func IsGlobalAdmin(user *casdoorsdk.User) bool
IsGlobalAdmin checks if the user is a system-level admin (IsAdmin flag only)
func IsIPAddress ¶
IsIPAddress checks if a string is a valid IP address (not a hostname)
func IsInternetIp ¶
func IsLocalhostTarget ¶
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 LoadCsvFile ¶
func LoadFactorFileByCsv ¶
func LoadFactorFileByCsv2 ¶
func LoadFactorFileBySpace ¶
func MatchTargetWithMachine ¶
MatchTargetWithMachine checks if a scan target matches the current machine based on hostname or IP addresses
func ParseFloat ¶
func ParseIntWithError ¶
func ReadBytesFromPath ¶
func ReadStringFromPath ¶
func ReturnAnyNotEmpty ¶
func SafeGoroutine ¶
func SafeGoroutine(fn func())
func StopOldInstance ¶
func StringsToFloats ¶
func StructToJson ¶
func StructToJson(v interface{}) string
func StructToJsonNoIndent ¶
func StructToJsonNoIndent(v interface{}) string
func WriteBytesToPath ¶
func WriteCsvFile ¶
func WriteStringToPath ¶
Types ¶
type LocationInfo ¶
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 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 ¶
New locator with dataFile
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)