test
This commit is contained in:
35
app/utils.go
35
app/utils.go
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -47,31 +46,9 @@ func decodeURL(tokenString string) (User, error) {
|
||||
return zero, nil
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
JWTSecret string
|
||||
Host string
|
||||
Port string
|
||||
ObfsPassword string
|
||||
SNI string
|
||||
NameFormat string
|
||||
}
|
||||
|
||||
var cfg *Config
|
||||
|
||||
func LoadConfig() {
|
||||
cfg = &Config{
|
||||
JWTSecret: os.Getenv("JWT_SECRET"),
|
||||
Host: os.Getenv("HOST"),
|
||||
Port: os.Getenv("PORT"),
|
||||
ObfsPassword: os.Getenv("OBFS_PASSWORD"),
|
||||
SNI: os.Getenv("SNI"),
|
||||
NameFormat: os.Getenv("NAME_FORMAT"),
|
||||
}
|
||||
}
|
||||
|
||||
var ip string
|
||||
|
||||
func LoadIP() {
|
||||
func LoadIP() string {
|
||||
res, err := http.Get("https://api.ipify.org")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -82,10 +59,18 @@ func LoadIP() {
|
||||
panic(err)
|
||||
}
|
||||
ip = string(data)
|
||||
log.Println(ip)
|
||||
return ip
|
||||
}
|
||||
func formatConfigName(format string, user User) string {
|
||||
s := strings.ReplaceAll(format, "{username}", user.Username)
|
||||
s = strings.ReplaceAll(s, "{host}", ip)
|
||||
return s
|
||||
}
|
||||
|
||||
func Ptr[T any](t T) *T { return &t }
|
||||
func Val[T any](t *T, def T) T {
|
||||
if t == nil {
|
||||
return def
|
||||
}
|
||||
return *t
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user