util

package
v1.37.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const Null = "N/A"

Variables

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

Functions

func CopyFile added in v1.35.0

func CopyFile(dest string, src string)

func EnsureFileFolderExists added in v1.35.0

func EnsureFileFolderExists(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 GenerateId

func GenerateId() string

func GetCurrentTime

func GetCurrentTime() string

func GetDescFromIP

func GetDescFromIP(ip string) string

func GetDescFromUserAgent

func GetDescFromUserAgent(userAgent string) string

func GetHostname added in v1.31.0

func GetHostname() string

func GetIPFromRequest

func GetIPFromRequest(req *http.Request) string

func GetIPInfo

func GetIPInfo(clientIP string) string

func GetIdFromOwnerAndName

func GetIdFromOwnerAndName(owner string, name string) string

func GetOwnerAndNameFromId

func GetOwnerAndNameFromId(id string) (string, string)

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 GetPath added in v1.35.0

func GetPath(path string) string

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()

func InitParser

func InitParser()

func InitWithData

func InitWithData(data []byte)

Init defaut locator with data

func JsonToStruct

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

func ListFiles

func ListFiles(path string) []string

func LogInfo

func LogInfo(ctx *context.Context, f string, v ...interface{})

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

func ReadStringFromPath

func ReadStringFromPath(path string) string

func SafeGoroutine added in v1.35.0

func SafeGoroutine(fn func())

func SnakeString

func SnakeString(s string) string

SnakeString transform XxYy to xx_yy

func StructToJson

func StructToJson(v interface{}) string

func WriteBytesToPath

func WriteBytesToPath(b []byte, path string)

func WriteStringToPath

func WriteStringToPath(s string, path string)

Types

type GlobalSession added in v1.35.0

type GlobalSession struct {
	Id          string
	Protocol    string
	Mode        string
	WebSocket   *websocket.Conn
	GuacdTunnel *guacamole.Tunnel
	Terminal    *term.Terminal
	Observer    *Manager

	Uptime   int64
	Hostname string
	// contains filtered or unexported fields
}

func (*GlobalSession) Close added in v1.35.0

func (s *GlobalSession) Close()

func (*GlobalSession) WriteString added in v1.35.0

func (s *GlobalSession) WriteString(str string) error

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

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 Manager added in v1.35.0

type Manager struct {
	// contains filtered or unexported fields
}
var GlobalSessionManager *Manager

func NewManager added in v1.35.0

func NewManager() *Manager

func NewObserver added in v1.35.0

func NewObserver(id string) *Manager

func (*Manager) Add added in v1.35.0

func (m *Manager) Add(s *GlobalSession)

func (*Manager) Clear added in v1.35.0

func (m *Manager) Clear()

func (*Manager) Delete added in v1.35.0

func (m *Manager) Delete(id string)

func (*Manager) Get added in v1.35.0

func (m *Manager) Get(id string) *GlobalSession

func (*Manager) Range added in v1.35.0

func (m *Manager) Range(f func(key string, value *GlobalSession))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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