consts.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package consts
  2. import (
  3. "os"
  4. "path/filepath"
  5. "strings"
  6. )
  7. const DataDirectory = "data"
  8. const DBFileName = "IP2LOCATION-LITE-DB3.BIN"
  9. var Config struct {
  10. AccessLogFile string `description:"Access log file"`
  11. DataDir string `description:"Application data directory"`
  12. DbUpdateTime int64 `default:"60" description:"Delay in minutes between database reloading"`
  13. Deployment string `default:"development" description:"Deployment type"`
  14. ErrorLogFile string `description:"Error log file"`
  15. Host string `default:"127.0.0.1" description:"Web server IP"`
  16. Port string `default:"8080" description:"Web server port"`
  17. WebURL string `default:"http://localhost:8080/" description:"Web server home URL"`
  18. }
  19. func DataPath() (string, error) {
  20. dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
  21. if err != nil {
  22. return dir, err
  23. }
  24. return strings.Join(append([]string{dir}, DataDirectory), string(os.PathSeparator)), nil
  25. }
  26. func DataPathFile(filename ...string) (string, error) {
  27. dir, err := filepath.Abs(Config.DataDir)
  28. if err != nil {
  29. return dir, err
  30. }
  31. return strings.Join(append([]string{dir}, filename...), string(os.PathSeparator)), nil
  32. }