common

package
v0.0.13-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddProxy

func AddProxy(
	sub *model.Subscription, autotest bool,
	lazy bool, clashType model.ClashType, proxies ...proxy.Proxy,
)

func AppendRules

func AppendRules(sub *model.Subscription, rules ...string)

func AppenddRuleProvider

func AppenddRuleProvider(
	sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
)

func BuildSub

func BuildSub(clashType model.ClashType, query model.SubConfig, template string, cacheExpire int64, retryTimes int) (
	*model.Subscription, error,
)

func FetchSubscriptionFromAPI

func FetchSubscriptionFromAPI(url string, userAgent string, retryTimes int) ([]byte, error)

func FetchSubscriptionUserInfo

func FetchSubscriptionUserInfo(url string, userAgent string, retryTimes int) (string, error)

func GetContryName

func GetContryName(countryKey string) string

func IsErrorCode

func IsErrorCode(err error, code ErrorCode) bool

IsErrorCode checks if an error has a specific error code

func LoadSubscription

func LoadSubscription(url string, refresh bool, userAgent string, cacheExpire int64, retryTimes int) ([]byte, error)

func LoadTemplate

func LoadTemplate(templatePath string) ([]byte, error)

func MKDir

func MKDir(dir string) error

func MergeSubAndTemplate

func MergeSubAndTemplate(temp *model.Subscription, sub *model.Subscription, igcg bool)

func MkEssentialDir

func MkEssentialDir() error

func PrependRuleProvider

func PrependRuleProvider(
	sub *model.Subscription, providerName string, group string, provider model.RuleProvider,
)

func PrependRules

func PrependRules(sub *model.Subscription, rules ...string)

func RandomString

func RandomString(length int) string

func Request

func Request(retryTimes int) *resty.Client

Types

type CommonError

type CommonError struct {
	Code    ErrorCode
	Message string
	Cause   error
}

CommonError represents a structured error type for the common package

func NewDatabaseConnectError

func NewDatabaseConnectError(cause error) *CommonError

Database errors

func NewDirAccessError

func NewDirAccessError(dirPath string, cause error) *CommonError

func NewDirCreationError

func NewDirCreationError(dirPath string, cause error) *CommonError

Directory errors

func NewError

func NewError(code ErrorCode, message string, cause error) *CommonError

NewError creates a new CommonError

func NewFileCreateError

func NewFileCreateError(filePath string, cause error) *CommonError

func NewFileNotFoundError

func NewFileNotFoundError(filePath string) *CommonError

File errors

func NewFileReadError

func NewFileReadError(filePath string, cause error) *CommonError

func NewFileWriteError

func NewFileWriteError(filePath string, cause error) *CommonError

func NewInvalidInputError

func NewInvalidInputError(paramName string, value string) *CommonError

func NewNetworkRequestError

func NewNetworkRequestError(url string, cause error) *CommonError

Network errors

func NewNetworkResponseError

func NewNetworkResponseError(message string, cause error) *CommonError

func NewRecordNotFoundError

func NewRecordNotFoundError(recordType string, id string) *CommonError

func NewRegexCompileError

func NewRegexCompileError(pattern string, cause error) *CommonError

Regex errors

func NewRegexInvalidError

func NewRegexInvalidError(paramName string, cause error) *CommonError

func NewSimpleError

func NewSimpleError(code ErrorCode, message string) *CommonError

NewSimpleError creates a new CommonError without a cause

func NewSubscriptionLoadError

func NewSubscriptionLoadError(url string, cause error) *CommonError

Subscription errors

func NewSubscriptionParseError

func NewSubscriptionParseError(cause error) *CommonError

func NewTemplateLoadError

func NewTemplateLoadError(template string, cause error) *CommonError

Template errors

func NewTemplateParseError

func NewTemplateParseError(cause error) *CommonError

func NewValidationError

func NewValidationError(field string, message string) *CommonError

Validation errors

func (*CommonError) Error

func (e *CommonError) Error() string

Error returns the string representation of the error

func (*CommonError) Is

func (e *CommonError) Is(target error) bool

Is allows error comparison

func (*CommonError) Unwrap

func (e *CommonError) Unwrap() error

Unwrap returns the underlying error

type ErrorCode

type ErrorCode string

ErrorCode represents different types of errors

const (
	// Directory operation errors
	ErrDirCreation ErrorCode = "DIRECTORY_CREATION_FAILED"
	ErrDirAccess   ErrorCode = "DIRECTORY_ACCESS_FAILED"

	// File operation errors
	ErrFileNotFound ErrorCode = "FILE_NOT_FOUND"
	ErrFileRead     ErrorCode = "FILE_READ_FAILED"
	ErrFileWrite    ErrorCode = "FILE_WRITE_FAILED"
	ErrFileCreate   ErrorCode = "FILE_CREATE_FAILED"

	// Network operation errors
	ErrNetworkRequest  ErrorCode = "NETWORK_REQUEST_FAILED"
	ErrNetworkResponse ErrorCode = "NETWORK_RESPONSE_FAILED"

	// Template and configuration errors
	ErrTemplateLoad  ErrorCode = "TEMPLATE_LOAD_FAILED"
	ErrTemplateParse ErrorCode = "TEMPLATE_PARSE_FAILED"
	ErrConfigInvalid ErrorCode = "CONFIG_INVALID"

	// Subscription errors
	ErrSubscriptionLoad  ErrorCode = "SUBSCRIPTION_LOAD_FAILED"
	ErrSubscriptionParse ErrorCode = "SUBSCRIPTION_PARSE_FAILED"

	// Regex errors
	ErrRegexCompile ErrorCode = "REGEX_COMPILE_FAILED"
	ErrRegexInvalid ErrorCode = "REGEX_INVALID"

	// Database errors
	ErrDatabaseConnect ErrorCode = "DATABASE_CONNECTION_FAILED"
	ErrDatabaseQuery   ErrorCode = "DATABASE_QUERY_FAILED"
	ErrRecordNotFound  ErrorCode = "RECORD_NOT_FOUND"

	// Validation errors
	ErrValidation   ErrorCode = "VALIDATION_FAILED"
	ErrInvalidInput ErrorCode = "INVALID_INPUT"
)

func GetErrorCode

func GetErrorCode(err error) (ErrorCode, bool)

GetErrorCode extracts the error code from an error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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