1
0
forked from tcp.direct/tcp.ac
tcp.ac/config.go

75 lines
1.5 KiB
Go
Raw Normal View History

2021-02-15 20:52:35 +00:00
package main
import (
"fmt"
2022-01-21 12:58:22 +00:00
"os"
"strconv"
2021-02-15 20:52:35 +00:00
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
2022-01-21 12:58:22 +00:00
// //////////// global declarations
2021-07-28 07:31:34 +00:00
var (
// config directives
2021-08-24 09:56:10 +00:00
debugBool bool
2022-01-21 12:58:22 +00:00
baseURL string
2021-08-24 09:56:10 +00:00
webPort string
webIP string
dbDir string
logDir string
uidSize int
keySize int
txtPort string
2021-09-01 07:19:10 +00:00
maxSize int
2021-07-28 07:31:34 +00:00
// utilitarian globals
err error
fn string
s string
i int
f *os.File
)
2021-02-15 20:52:35 +00:00
func configRead() {
// name of the file
// and the extension
viper.SetConfigName("config")
viper.SetConfigType("toml")
// potential config paths
viper.AddConfigPath("/etc/tcpac/")
viper.AddConfigPath("../")
viper.AddConfigPath("./")
// this should be replaced with more intelligent handling
err = viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error reading config file: %s \n", err))
}
// read config
debugBool = viper.GetBool("global.debug") // we need to load the debug boolean first
if debugBool {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
log.Debug().Msg("Debug mode enabled")
} else {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
2022-01-21 12:58:22 +00:00
baseURL = viper.GetString("http.baseurl")
2021-02-15 20:52:35 +00:00
2021-07-28 07:31:34 +00:00
i := viper.GetInt("http.port")
webPort = strconv.Itoa(i)
2021-02-15 20:52:35 +00:00
2021-07-28 07:31:34 +00:00
webIP = viper.GetString("http.bindip")
dbDir = viper.GetString("files.data")
logDir = viper.GetString("files.logs")
uidSize = viper.GetInt("global.uidsize")
keySize = viper.GetInt("global.delkeysize")
txtPort = viper.GetString("txt.port")
2021-09-01 07:19:10 +00:00
maxSize = viper.GetInt("files.maxuploadsize")
2021-04-24 05:31:18 +00:00
//
2021-02-15 20:52:35 +00:00
}