package conf

import (
	"encoding/json"
	"fmt"
	"os"

	"github.com/name5566/leaf/log"

	"server/tools"
)

var Server struct {
	LogLevel    string
	LogPath     string
	WSAddr      string
	CertFile    string
	KeyFile     string
	TCPAddr     string
	MaxConnNum  int
	ConsolePort int
	ProfilePath string
}

func init() {
	var path string
	if tools.IsDebug {
		path = fmt.Sprintf("../../bin/conf/server_%s.json", "debug")
	} else {
		// path = fmt.Sprintf("../../bin/conf/server_%s.json", "release")
		path = fmt.Sprintf("/home/ludo_server/bin/conf/server_%s.json", "release")
	}
	data, err := os.ReadFile(path)
	if err != nil {
		log.Fatal("%v", err)
	}
	err = json.Unmarshal(data, &Server)
	if err != nil {
		log.Fatal("%v", err)
	}
}
