consts.go 1.3 KB

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