util

package
v1.108.26 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 20 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 ClientIPFromCtx added in v1.108.15

func ClientIPFromCtx(c *zip.Ctx) string

ClientIPFromCtx resolves the formatted client-IP description from a ZAP request context — the ZAP counterpart of GetIPFromRequest.

func FileExist

func FileExist(path string) bool

func FilterField

func FilterField(field string) bool

func FilterQuery

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

func GetClientIP added in v1.108.15

func GetClientIP(xForwardedFor, remoteAddr string) string

GetClientIP formats the client IP description from the raw x-forwarded-for header and the transport remote address — the transport-agnostic core shared by the net/http path (GetIPFromRequest) and the ZAP path (a zip.Ctx hands the header plus its fasthttp RemoteAddr). x-forwarded-for wins; otherwise the remote address host is parsed (IPv4 host:port or bracketed IPv6).

func GetCurrentTime

func GetCurrentTime() string

func GetDescFromIP

func GetDescFromIP(ip string) string

func GetDescFromUserAgent

func GetDescFromUserAgent(userAgent string) 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 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(c *zip.Ctx, f string, v ...interface{})

LogInfo writes a request-scoped info line prefixed with the caller IP, read from the ZAP request context (x-forwarded-for, else the fasthttp remote addr).

func Paginate added in v1.108.15

func Paginate(page string, perPage int, total int64) (offset int, nums int64)

Paginate is the ONE offset/total helper the list handlers use, replacing Beego's pagination.SetPaginator: given the 1-based page string, the page size and the total row count, it returns the SQL offset and the total (echoed back to the client as data2 for its own page math). page < 1 clamps to the first page, matching Beego's Paginator.Page() lower bound.

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 SnakeString

func SnakeString(s string) string

SnakeString transform XxYy to xx_yy

The output names a SQL column (see the ORDER BY and LIKE call sites in object/), so it is schema, not cosmetics. Two rules are load-bearing and both have a test in string_test.go:

  • Every capital gets its own separator, acronyms included: "OrgID" is "org_i_d", not "org_id". That is how the live columns were named.
  • A leading underscore already separates, so no second one is emitted: "_Foo" is "_foo", not "__foo".

func StructToJson

func StructToJson(v interface{}) string

func WriteBytesToPath

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

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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