diff --git a/internal/library/env.go b/internal/library/env.go index 39d9f03d3..21e5d8f6d 100644 --- a/internal/library/env.go +++ b/internal/library/env.go @@ -7,7 +7,6 @@ import ( "maps" "os" "path/filepath" - "regexp" "slices" "strings" "unicode/utf8" @@ -16,6 +15,7 @@ import ( "github.com/tidwall/gjson" "github.com/tidwall/jsonc" "github.com/yetone/magpie/internal/edit" + "github.com/yetone/magpie/internal/lazyre" ) // Environment variables (paopao_baobao on X) are set once in the library @@ -54,7 +54,7 @@ const ( maxEnvValue = 8192 ) -var envName = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`) +var envName = lazyre.New(`^[A-Za-z_][A-Za-z0-9_]*$`) func (e *EnvVar) check() error { if !envName.MatchString(e.Name) || len(e.Name) > maxEnvName { diff --git a/internal/provider/alibaba_usage.go b/internal/provider/alibaba_usage.go index 7f0c67722..b867516d0 100644 --- a/internal/provider/alibaba_usage.go +++ b/internal/provider/alibaba_usage.go @@ -38,12 +38,13 @@ import ( "io" "net/http" "net/url" - "regexp" "sort" "strconv" "strings" "sync" "time" + + "github.com/yetone/magpie/internal/lazyre" ) const ( @@ -371,7 +372,7 @@ func aliGateway(ctx context.Context, token string, site aliSite) ([]byte, error) return node, nil } -var aliWindowField = regexp.MustCompile(`^per(\d+)(Hour|Day|Week|Month)(Percentage|ResetTime)$`) +var aliWindowField = lazyre.New(`^per(\d+)(Hour|Day|Week|Month)(Percentage|ResetTime)$`) // aliReadWindows reads the perPercentage and ResetTime pairs of // the usage data as windows, the shortest first. Percentage is the share