feat: update to go1.24 & support listening https (#1002)

* feat: support listening https

* refactor

* modernize

* support snake case in config

* more precise control of config fields

* update goreleaser config

* remove kubeyaml

* fix: expose agent_secret

* chore
This commit is contained in:
UUBulb
2025-02-28 22:02:54 +08:00
committed by GitHub
parent e770398a11
commit 1d2f8d24f6
28 changed files with 321 additions and 175 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"cmp"
"crypto/rand"
"errors"
"iter"
@@ -13,24 +14,19 @@ import (
"strings"
"golang.org/x/exp/constraints"
jsoniter "github.com/json-iterator/go"
)
var (
Json = jsoniter.ConfigCompatibleWithStandardLibrary
DNSServers = []string{"8.8.8.8:53", "8.8.4.4:53", "1.1.1.1:53", "1.0.0.1:53"}
)
var ipv4Re = regexp.MustCompile(`(\d*\.).*(\.\d*)`)
ipv4Re = regexp.MustCompile(`(\d*\.).*(\.\d*)`)
ipv6Re = regexp.MustCompile(`(\w*:\w*:).*(:\w*:\w*)`)
)
func ipv4Desensitize(ipv4Addr string) string {
return ipv4Re.ReplaceAllString(ipv4Addr, "$1****$2")
}
var ipv6Re = regexp.MustCompile(`(\w*:\w*:).*(:\w*:\w*)`)
func ipv6Desensitize(ipv6Addr string) string {
return ipv6Re.ReplaceAllString(ipv6Addr, "$1****$2")
}
@@ -51,9 +47,11 @@ func IPStringToBinary(ip string) ([]byte, error) {
}
func BinaryToIPString(b []byte) string {
var addr16 [16]byte
copy(addr16[:], b)
addr := netip.AddrFrom16(addr16)
if len(b) < 16 {
return "::"
}
addr := netip.AddrFrom16([16]byte(b))
return addr.Unmap().String()
}
@@ -74,7 +72,7 @@ func GenerateRandomString(n int) (string, error) {
const letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
lettersLength := big.NewInt(int64(len(letters)))
ret := make([]byte, n)
for i := 0; i < n; i++ {
for i := range n {
num, err := rand.Int(rand.Reader, lettersLength)
if err != nil {
return "", err
@@ -117,22 +115,35 @@ func MapValuesToSlice[Map ~map[K]V, K comparable, V any](m Map) []V {
return slices.AppendSeq(s, maps.Values(m))
}
func Unique[T comparable](s []T) []T {
m := make(map[T]struct{})
ret := make([]T, 0, len(s))
for _, v := range s {
if _, ok := m[v]; !ok {
m[v] = struct{}{}
ret = append(ret, v)
}
}
return ret
func MapKeysToSlice[Map ~map[K]V, K comparable, V any](m Map) []K {
s := make([]K, 0, len(m))
return slices.AppendSeq(s, maps.Keys(m))
}
func ConvertSeq[T, U any](seq iter.Seq[T], f func(e T) U) iter.Seq[U] {
return func(yield func(U) bool) {
for e := range seq {
if !yield(f(e)) {
func Unique[S ~[]E, E cmp.Ordered](list S) S {
if list == nil {
return nil
}
out := make([]E, len(list))
copy(out, list)
slices.Sort(out)
return slices.Compact(out)
}
func ConvertSeq[In, Out any](seq iter.Seq[In], f func(In) Out) iter.Seq[Out] {
return func(yield func(Out) bool) {
for in := range seq {
if !yield(f(in)) {
return
}
}
}
}
func ConvertSeq2[KIn, VIn, KOut, VOut any](seq iter.Seq2[KIn, VIn], f func(KIn, VIn) (KOut, VOut)) iter.Seq2[KOut, VOut] {
return func(yield func(KOut, VOut) bool) {
for k, v := range seq {
if !yield(f(k, v)) {
return
}
}