feat: read config from env (#104)

* feat: read config from env

* ci: skip some tests
This commit is contained in:
UUBulb
2024-11-30 11:40:48 +08:00
committed by GitHub
parent 48093faf98
commit ea6f119e72
9 changed files with 181 additions and 114 deletions
+32
View File
@@ -4,6 +4,7 @@ import (
"net/http"
"os"
"strings"
"sync"
jsoniter "github.com/json-iterator/go"
)
@@ -48,3 +49,34 @@ func RemoveDuplicate[T comparable](sliceList []T) []T {
}
return list
}
// OnceValue returns a function that invokes f only once and returns the value
// returned by f. The returned function may be called concurrently.
//
// If f panics, the returned function will panic with the same value on every call.
func OnceValue[T any](f func() T) func() T {
var (
once sync.Once
valid bool
p any
result T
)
g := func() {
defer func() {
p = recover()
if !valid {
panic(p)
}
}()
result = f()
f = nil
valid = true
}
return func() T {
once.Do(g)
if !valid {
panic(p)
}
return result
}
}
+5
View File
@@ -2,6 +2,7 @@ package utls_test
import (
"net/http"
"os"
"testing"
utls "github.com/refraction-networking/utls"
@@ -13,6 +14,10 @@ import (
const url = "https://www.patreon.com/login"
func TestCloudflareDetection(t *testing.T) {
if ci := os.Getenv("CI"); ci != "" { // skip if test on CI
return
}
client := http.DefaultClient
t.Logf("testing connection to %s", url)