This commit is contained in:
GoEdgeLab
2024-07-27 14:15:25 +08:00
parent be70925770
commit 5a17ae9d79
520 changed files with 2515 additions and 762 deletions

View File

@@ -3,8 +3,9 @@
package utils
import (
"github.com/iwind/TeaGo/maps"
"sync"
"github.com/iwind/TeaGo/maps"
)
type CacheMap struct {

View File

@@ -3,8 +3,9 @@
package utils
import (
"github.com/iwind/TeaGo/assert"
"testing"
"github.com/iwind/TeaGo/assert"
)
func TestNewCacheMap(t *testing.T) {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils

View File

@@ -1,10 +1,11 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils_test
import (
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
)
func TestEqualConfig(t *testing.T) {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils

View File

@@ -1,4 +1,4 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package domainutils
@@ -14,7 +14,7 @@ func ValidateDomainFormat(domain string) bool {
if piece == "-" ||
strings.HasPrefix(piece, "-") ||
strings.HasSuffix(piece, "-") ||
//strings.Contains(piece, "--") ||
// strings.Contains(piece, "--") ||
len(piece) > 63 ||
// 支持中文、大写字母、下划线
!regexp.MustCompile(`^[\p{Han}_a-zA-Z0-9-]+$`).MatchString(piece) {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils

View File

@@ -1,11 +1,12 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils_test
import (
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestValidateEmail(t *testing.T) {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package executils

View File

@@ -1,11 +1,12 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package executils_test
import (
executils "github.com/TeaOSLab/EdgeAPI/internal/utils/exec"
"testing"
"time"
executils "github.com/TeaOSLab/EdgeAPI/internal/utils/exec"
)
func TestNewTimeoutCmd_Sleep(t *testing.T) {

View File

@@ -1,14 +1,15 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
//go:build linux
package executils
import (
"golang.org/x/sys/unix"
"io/fs"
"os"
"os/exec"
"syscall"
"golang.org/x/sys/unix"
)
// LookPath customize our LookPath() function, to work in broken $PATH environment variable
@@ -56,4 +57,3 @@ func LookPath(file string) (string, error) {
Err: exec.ErrNotFound,
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
//go:build !linux
package executils

View File

@@ -3,9 +3,10 @@
package expires
import (
"testing"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/logs"
"testing"
)
func TestNewIdKeyMap(t *testing.T) {

View File

@@ -1,8 +1,9 @@
package expires
import (
"github.com/TeaOSLab/EdgeAPI/internal/zero"
"sync"
"github.com/TeaOSLab/EdgeAPI/internal/zero"
)
type ItemMap = map[uint64]zero.Zero

View File

@@ -1,14 +1,15 @@
package expires
import (
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/logs"
timeutil "github.com/iwind/TeaGo/utils/time"
"math"
"runtime"
"testing"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/logs"
timeutil "github.com/iwind/TeaGo/utils/time"
)
func TestList_Add(t *testing.T) {

View File

@@ -3,10 +3,11 @@
package expires
import (
"github.com/TeaOSLab/EdgeAPI/internal/goman"
"github.com/TeaOSLab/EdgeAPI/internal/zero"
"sync"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/goman"
"github.com/TeaOSLab/EdgeAPI/internal/zero"
)
var SharedManager = NewManager()

View File

@@ -1,13 +1,14 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils
import (
"os/exec"
"runtime"
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
executils "github.com/TeaOSLab/EdgeAPI/internal/utils/exec"
"github.com/iwind/TeaGo/types"
"os/exec"
"runtime"
)
func AddPortsToFirewall(ports []int) {

View File

@@ -1,4 +1,4 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils

View File

@@ -1,12 +1,13 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils_test
import (
"errors"
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/iwind/TeaGo/logs"
"testing"
)
func TestJSONClone(t *testing.T) {

View File

@@ -2,6 +2,8 @@ package utils
import (
"errors"
"sync"
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
"github.com/TeaOSLab/EdgeAPI/internal/utils/taskutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
@@ -10,7 +12,6 @@ import (
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/logs"
"github.com/miekg/dns"
"sync"
)
var sharedDNSClient *dns.Client

View File

@@ -3,9 +3,10 @@
package utils_test
import (
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"testing"
)
func TestLookupCNAME(t *testing.T) {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package maputils

View File

@@ -1,11 +1,12 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package maputils_test
import (
"testing"
maputils "github.com/TeaOSLab/EdgeAPI/internal/utils/maps"
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestNewFixedMap(t *testing.T) {

View File

@@ -1,4 +1,4 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils

View File

@@ -1,11 +1,12 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils_test
import (
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestIsValidMobile(t *testing.T) {

View File

@@ -2,9 +2,10 @@ package numberutils
import (
"fmt"
"github.com/iwind/TeaGo/types"
"strconv"
"strings"
"github.com/iwind/TeaGo/types"
)
func FormatInt64(value int64) string {

View File

@@ -1,11 +1,12 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package numberutils_test
import (
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
"math"
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils"
)
func TestMax(t *testing.T) {

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils

View File

@@ -1,4 +1,4 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package regexputils

View File

@@ -1,11 +1,12 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package regexputils_test
import (
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestExpr(t *testing.T) {

View File

@@ -1,14 +1,15 @@
package utils
import (
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/files"
"github.com/iwind/TeaGo/logs"
"log"
"os"
"path/filepath"
"runtime"
"sync"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/files"
"github.com/iwind/TeaGo/logs"
)
// 服务管理器

View File

@@ -5,13 +5,14 @@ package utils
import (
"errors"
"os"
"os/exec"
"regexp"
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
executils "github.com/TeaOSLab/EdgeAPI/internal/utils/exec"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/files"
"os"
"os/exec"
"regexp"
)
var systemdServiceFile = "/etc/systemd/system/edge-api.service"

View File

@@ -1,8 +1,9 @@
package utils
import (
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
"testing"
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
)
func TestServiceManager_Log(t *testing.T) {

View File

@@ -5,12 +5,13 @@ package utils
import (
"fmt"
"os/exec"
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
"github.com/iwind/TeaGo/Tea"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/mgr"
"os/exec"
)
// 安装服务

View File

@@ -1,14 +1,15 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils
import (
"crypto/sha1"
"fmt"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
"sync/atomic"
"time"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
)
const sha1RandomPrefix = "SHA1_RANDOM"

View File

@@ -1,11 +1,12 @@
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2022 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package utils_test
import (
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/iwind/TeaGo/types"
"testing"
)
func TestSha1Random(t *testing.T) {

View File

@@ -3,9 +3,10 @@
package sizes_test
import (
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils/sizes"
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestSizes(t *testing.T) {

View File

@@ -3,6 +3,7 @@
package utils
import (
"github.com/iwind/TeaGo/lists"
"strings"
)
@@ -133,3 +134,12 @@ func parseKeywordValue(value string) (arg splitArg) {
}
return
}
func ListIsGreaterEqualThanOther(list []string, otherList []string) bool {
for _, v := range otherList {
if !lists.Contains(list, v) {
return false
}
}
return true
}

View File

@@ -3,9 +3,10 @@
package utils_test
import (
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/iwind/TeaGo/assert"
"testing"
)
func TestSplitStrings(t *testing.T) {

View File

@@ -3,8 +3,9 @@
package utils_test
import (
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
)
func TestSystemMemoryGB(t *testing.T) {

View File

@@ -1,4 +1,4 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package taskutils

View File

@@ -1,11 +1,12 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package taskutils_test
import (
"github.com/TeaOSLab/EdgeAPI/internal/utils/taskutils"
"sync"
"testing"
"github.com/TeaOSLab/EdgeAPI/internal/utils/taskutils"
)
func TestRunConcurrent(t *testing.T) {

View File

@@ -4,10 +4,11 @@ package testutils
import (
"fmt"
timeutil "github.com/iwind/TeaGo/utils/time"
"runtime"
"testing"
"time"
timeutil "github.com/iwind/TeaGo/utils/time"
)
func StartMemoryStatsGC(t *testing.T) {

View File

@@ -2,13 +2,14 @@ package utils
import (
"fmt"
"regexp"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/errors"
"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/types"
timeutil "github.com/iwind/TeaGo/utils/time"
"regexp"
"time"
)
// 分钟时间点

View File

@@ -1,9 +1,10 @@
package utils_test
import (
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"testing"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
)
func TestRangeDays(t *testing.T) {

View File

@@ -1,8 +1,9 @@
package ttlcache
import (
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
)
var SharedCache = NewCache()

View File

@@ -1,16 +1,17 @@
package ttlcache
import (
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeAPI/internal/utils/testutils"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
"runtime"
"strconv"
"sync/atomic"
"testing"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeAPI/internal/utils/testutils"
"github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/types"
)
func TestNewCache(t *testing.T) {

View File

@@ -3,10 +3,11 @@
package ttlcache
import (
"github.com/TeaOSLab/EdgeAPI/internal/goman"
"github.com/TeaOSLab/EdgeAPI/internal/zero"
"sync"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/goman"
"github.com/TeaOSLab/EdgeAPI/internal/zero"
)
var SharedManager = NewManager()

View File

@@ -1,11 +1,12 @@
package ttlcache
import (
"sync"
"time"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeAPI/internal/utils/expires"
"github.com/iwind/TeaGo/types"
"sync"
"time"
)
type Piece struct {

View File

@@ -1,9 +1,10 @@
package ttlcache
import (
"github.com/iwind/TeaGo/rands"
"testing"
"time"
"github.com/iwind/TeaGo/rands"
)
func TestPiece_Add(t *testing.T) {

View File

@@ -1,9 +1,10 @@
package utils
import (
"time"
"github.com/TeaOSLab/EdgeAPI/internal/goman"
"github.com/iwind/TeaGo/types"
"time"
)
var unixTime = time.Now().Unix()

View File

@@ -1,9 +1,10 @@
package utils
import (
"testing"
"github.com/iwind/TeaGo/Tea"
_ "github.com/iwind/TeaGo/bootstrap"
"testing"
)
func TestUnzip_Run(t *testing.T) {