test
This commit is contained in:
44
app/config.go
Normal file
44
app/config.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
JWTSecret string
|
||||
Host string
|
||||
SNI string
|
||||
NameFormat string
|
||||
}
|
||||
|
||||
var cfg *Config
|
||||
var hysteriaCfg *HysteriaConfig
|
||||
|
||||
func LoadConfig() {
|
||||
cfg = &Config{
|
||||
JWTSecret: os.Getenv("JWT_SECRET"),
|
||||
Host: LoadIP(),
|
||||
SNI: os.Getenv("SNI"),
|
||||
NameFormat: os.Getenv("NAME_FORMAT"),
|
||||
}
|
||||
hysteriaCfg = &HysteriaConfig{}
|
||||
|
||||
f, err := os.Open("config.yaml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
data, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = yaml.Unmarshal(data, hysteriaCfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println(cfg, hysteriaCfg)
|
||||
}
|
||||
Reference in New Issue
Block a user