This commit is contained in:
2026-03-04 18:23:00 +03:00
parent b81df5866b
commit 205d9cf8b0
15 changed files with 439 additions and 165 deletions

View File

@@ -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
}