utils

package
v0.0.45 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: GPL-3.0 Imports: 29 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func ControlSystemService added in v0.0.32

func ControlSystemService(args []string, action string, run func()) error

func CreateSystemService added in v0.0.34

func CreateSystemService(args []string, run func()) (service.Service, error)

func EncodeBase64 added in v0.0.32

func EncodeBase64(data string) string

func GetIntValueFromStr

func GetIntValueFromStr(c context.Context, key string) (int, bool)

func GetJwtToken

func GetJwtToken(secretKey string, iat, seconds int64, payload string) (string, error)

@secretKey: JWT 加解密密钥 @iat: 时间戳 @seconds: 过期时间,单位秒 @payload: 数据载体

func GetJwtTokenFromMap

func GetJwtTokenFromMap(secretKey string, iat, seconds int64, payload map[string]string) (string, error)

@secretKey: JWT 加解密密钥 @iat: 时间戳 @seconds: 过期时间,单位秒 @payload: 数据载体

func GetValue

func GetValue[T any](c context.Context, key string) (T, bool)

func HashPassword

func HashPassword(password string) (string, error)

func InstallToSystemPath added in v0.0.32

func InstallToSystemPath(installPath string) error

func IsInteger

func IsInteger(str string) bool

func IsSameDay added in v0.0.31

func IsSameDay(first time.Time, second time.Time) bool

func LoadClientConfig

func LoadClientConfig(content []byte, strict bool) (
	*v1.ClientCommonConfig,
	[]v1.ProxyConfigurer,
	[]v1.VisitorConfigurer,
	error,
)

func LoadClientConfigNormal

func LoadClientConfigNormal(content []byte, strict bool) (*v1.ClientConfig, error)

func LoadConfigureFromContent

func LoadConfigureFromContent(content []byte, c any, strict bool) error

func LoadContentWithTemplate

func LoadContentWithTemplate(content []byte, values *config.Values) ([]byte, error)

func LoadServerConfig

func LoadServerConfig(content []byte, strict bool) (*v1.ServerConfig, error)

func MD5

func MD5[T []byte | string](input T) string

func NewBaseFRPClientConfig

func NewBaseFRPClientConfig(serverAddr string, serverPort int, token string) *v1.ClientCommonConfig

func NewBaseFRPClientUserAuthConfig

func NewBaseFRPClientUserAuthConfig(serverAddr string, serverPort int, user, token string) *v1.ClientCommonConfig

func NewBaseFRPServerConfig

func NewBaseFRPServerConfig(port int, token string) *v1.ServerConfig

func NewBaseFRPServerUserAuthConfig

func NewBaseFRPServerUserAuthConfig(port int, opts []v1.HTTPPluginOptions) *v1.ServerConfig

func ParseToken

func ParseToken(secretKey, tokenStr string) (u jwt.MapClaims, err error)

func PemBlockForPrivKey

func PemBlockForPrivKey(priv interface{}) *pem.Block

func PublicKey

func PublicKey(priv interface{}) interface{}

func SHA1

func SHA1(input string) string

func Str2Int64

func Str2Int64(str string) int64

func Str2Int64Default

func Str2Int64Default(str string, intVal int64) int64

func TLSClientCert

func TLSClientCert(caPem []byte) (credentials.TransportCredentials, error)

func TLSClientCertNoValidate

func TLSClientCertNoValidate(caPem []byte) (credentials.TransportCredentials, error)

func TLSServerCert

func TLSServerCert(certPem, keyPem []byte) (credentials.TransportCredentials, error)

func ToStr

func ToStr(any interface{}) string

func TransformProxyConfigurerToMap

func TransformProxyConfigurerToMap(origin v1.ProxyConfigurer) (key string, r v1.ProxyConfigurer)

func TransformVisitorConfigurerToMap

func TransformVisitorConfigurerToMap(origin v1.VisitorConfigurer) (key string, r v1.VisitorConfigurer)

func ValidateJwtToken

func ValidateJwtToken(secretKey, token string) (bool, error)

@secretKey: JWT 加解密密钥 @token: JWT Token 的字符串

Types

type SyncMap added in v0.0.32

type SyncMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SyncMap is like a Go sync.Map but type-safe using generics.

The zero SyncMap is empty and ready for use. A SyncMap must not be copied after first use.

func (*SyncMap[K, V]) Clone added in v0.0.32

func (s *SyncMap[K, V]) Clone() SyncMap[K, V]

Clone returns a copy (clone) of current SyncMap.

func (*SyncMap[K, V]) Delete added in v0.0.32

func (s *SyncMap[K, V]) Delete(key K)

Delete deletes the value for a key.

func (*SyncMap[K, V]) Grow added in v0.0.32

func (s *SyncMap[K, V]) Grow(size int)

Grow grows the map to the given size. It can be called before the first write operation used.

func (*SyncMap[K, V]) Keys added in v0.0.32

func (s *SyncMap[K, V]) Keys() []K

Keys return slice with all map keys.

func (*SyncMap[K, V]) Len added in v0.0.32

func (s *SyncMap[K, V]) Len() (l int)

Len returns the count of values in the map.

func (*SyncMap[K, V]) Load added in v0.0.32

func (s *SyncMap[K, V]) Load(key K) (value V, loaded bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*SyncMap[K, V]) LoadAndDelete added in v0.0.32

func (s *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*SyncMap[K, V]) LoadOrStore added in v0.0.32

func (s *SyncMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*SyncMap[K, V]) Range added in v0.0.32

func (s *SyncMap[K, V]) Range(f func(key K, value V) (shouldContinue bool))

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once. Range does not block other methods on the receiver; even f itself may call any method on m.

func (*SyncMap[K, V]) Store added in v0.0.32

func (s *SyncMap[K, V]) Store(key K, value V)

Store sets the value for a key.

func (*SyncMap[K, V]) Values added in v0.0.32

func (s *SyncMap[K, V]) Values() []V

Values return slice with all map values.

type SystemService added in v0.0.32

type SystemService struct {
	service.Service
	// contains filtered or unexported fields
}

func (*SystemService) Start added in v0.0.32

func (ss *SystemService) Start(s service.Service) error

func (*SystemService) Stop added in v0.0.32

func (ss *SystemService) Stop(s service.Service) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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