50 lines
869 B
Go
50 lines
869 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
NetInterface string `json:"net_interface"`
|
|
Htdocs string `json:"htdocs"`
|
|
Profile bool `json:"profile"`
|
|
}
|
|
|
|
var static_config *Config = nil
|
|
|
|
func GetConfig() *Config {
|
|
if static_config != nil {
|
|
return static_config
|
|
}
|
|
|
|
file, err := os.Open("config.json")
|
|
if err != nil {
|
|
fmt.Println("No config file found")
|
|
return &Config{
|
|
NetInterface: "127.0.0.1:80",
|
|
Htdocs: "./htdocs",
|
|
Profile: false,
|
|
}
|
|
}
|
|
defer file.Close()
|
|
|
|
var config Config
|
|
err = json.NewDecoder(file).Decode(&config)
|
|
if err != nil {
|
|
fmt.Println("Error decoding config file:", err)
|
|
return &Config{
|
|
NetInterface: "127.0.0.1:80",
|
|
Htdocs: "./htdocs",
|
|
Profile: false,
|
|
}
|
|
}
|
|
static_config = &config
|
|
return &config
|
|
}
|
|
|
|
func ResetConfig() {
|
|
static_config = nil
|
|
}
|