utils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CACHESIZE                = 1 * 1024 * 1024 // Note value size larger than 1/1024 of total cache size will not be cached
	EXPIRE_GRPC_DNS          = 60 * 60 * 2
	EXPIRE_GRPC_SMARTSENCE   = 60 * 60 * 2
	EXPIRE_LINKER_LEASE      = 60 * 5
	EXPIRE_LOG_TIMEGAP       = 5 // 日志打印时间间隔,单位秒
	EXPIRE_LINKER_PEER       = 60
	EXPIRE_PEER_POLICY_IP    = 10
	EXPIRE_USER_FORBIDDEN_IP = 10
	EXPIRE                   = 0
)
View Source
const (
	DefaultSet     = "defaultset"
	DefaultSetV6   = "defaultset_v6"
	WhitelistSet   = "whitelistset"
	WhitelistSetV6 = "whitelistset_v6"
	BlacklistSet   = "blacklistset"
	BlacklistSetV6 = "blacklistset_v6"
	TempSet        = "tempset"
	TempSetV6      = "tempset_v6"
)
View Source
const (
	POLICY_ACCEPT = iota
	POLICY_DROP
	POLICY_REJECT
)
View Source
const (
	APITOKEN = "x&Clouddeep@BJ2023#!@#."
)
View Source
const (
	// ContentType ContentType
	ContentType string = "application/x-www-form-urlencoded"
)

Variables

View Source
var (
	Marshal          = json.Marshal
	UnmarshalX       = json.Unmarshal
	MarshalIndent    = json.MarshalIndent
	MarshalToStringX = json.MarshalToString
	NewDecoder       = json.NewDecoder
	NewEncoder       = json.NewEncoder
)

定义JSON操作

Functions

func AesDecrypt

func AesDecrypt(str string) (string, error)

AesDecrypt aes解密

func AesEncrypt

func AesEncrypt(str string) (string, error)

func Base64

func Base64(value []byte) string

func CacheDeleteValue

func CacheDeleteValue(key string) bool

func CacheReadValue

func CacheReadValue(key string) string

func CacheWriteValue

func CacheWriteValue(key, value string, timeout int) error

func CatchPanic

func CatchPanic()

func CatchPanicThenRun

func CatchPanicThenRun(catchFun func())

func Compression

func Compression(data string) ([]byte, error)

func DecodeString

func DecodeString(s string) ([]byte, error)

func Decompression

func Decompression(data string) (string, error)

func EncodingString

func EncodingString(s []byte) string

func FormatCacheKey

func FormatCacheKey(strs ...string) string

func GenerateRsaKey

func GenerateRsaKey(bits int) (string, string)

func Get

func Get(url string) (string, error)

Get access web service

func GetDB

func GetDB() *gorm.DB

func GetLocalOutboundAddress

func GetLocalOutboundAddress() net.IP

func GetMacAddress

func GetMacAddress(ip string) string

func GetRandomUint32

func GetRandomUint32() (r uint32)

func HMACSha256

func HMACSha256(key, value string) []byte

func HashFile

func HashFile(method string, fileName string) (string, error)

func MD5

func MD5(value string) string

func MarshalToString

func MarshalToString(v any) string

MarshalToString JSON编码为字符串

func NewGorm

func NewGorm(host, u, p, db string, isencrypt bool) error

func NewUUID

func NewUUID() (string, error)

func ParseBool

func ParseBool(v int) bool

func ParseInt

func ParseInt(v string) int

func ParseInt64ToInt

func ParseInt64ToInt(v int64) int

func ParseUInt64

func ParseUInt64(v string) uint64

func RandNumber

func RandNumber() int

func ReadWholeFile

func ReadWholeFile(fileName string) (string, error)

func Request

func Request(url, method string, str string, header map[string]string) (string, error)

func Run

func Run(command string, in string, args ...string) (string, string, error)

func Unmarshal

func Unmarshal(v []byte, o any) error

func WatchFile

func WatchFile(file string, callback func()) io.Closer

Types

type IPSet

type IPSet struct {
	Binary string // Binary is Command path
	Wait   bool
}

func NewIPSet

func NewIPSet(wait bool) (*IPSet, error)

NewIPSet new ipset @Return: *IPSet, error Note: need root to run

func (*IPSet) Add

func (ipset *IPSet) Add(ipType IPTYPE, t int, expire int, args ...string) (string, error)

func (*IPSet) GetDefaultName

func (ipset *IPSet) GetDefaultName(ipType IPTYPE, t int) string

func (*IPSet) GetIpsetName

func (ipset *IPSet) GetIpsetName(ipType IPTYPE, t int) string

func (*IPSet) Run

func (ipset *IPSet) Run(ctx context.Context, args ...string) (string, error)

type IPTYPE

type IPTYPE int32
const (
	IPV6 IPTYPE = 1
	IPV4 IPTYPE = 2
)

type IPTables

type IPTables struct {
	Binary          string
	InputPolicy     int
	ForwardPolicy   int
	OutputPolicy    int
	AcceptInputMode bool
}

func NewIPTables

func NewIPTables() (*IPTables, error)

Note: need root to run

func (*IPTables) AcceptAllInput

func (table *IPTables) AcceptAllInput()

func (*IPTables) ResetAllInput

func (table *IPTables) ResetAllInput()

type WaitPool

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

func NewWaitPool

func NewWaitPool(max uint32, new func() any) *WaitPool

func (*WaitPool) Get

func (p *WaitPool) Get() any

func (*WaitPool) Put

func (p *WaitPool) Put(x any)

Jump to

Keyboard shortcuts

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