simplefileshare/config.go
2021-08-31 19:07:19 +05:00

48 lines
828 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"errors"
"fmt"
"os"
"github.com/BurntSushi/toml"
log "github.com/sirupsen/logrus"
)
var config *Config
type Config struct {
ListenAddress string
StoragePath string
RemoveFilePeriod uint // hours
LogLevel log.Level
}
func initConfig() error {
log.Debugln("Сonfig initialization started.")
defer log.Debugln("Сonfig initialization finished.")
var configFilePath string
if len(os.Args) < 2 {
configFilePath = defaultConfigFilePath
} else {
configFilePath = os.Args[1]
}
_, err := toml.DecodeFile(configFilePath, &config)
if err != nil {
return err
}
stat, err := os.Stat(config.StoragePath)
if err != nil {
return fmt.Errorf("os.Stat(config.StoragePath): %v", err)
}
if !stat.IsDir() {
return errors.New("StoragePath is not a dir")
}
return nil
}