consts.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. LimitRequests int `default:"5" description:"Requests per second per one IP"`
  17. Port string `default:"8080" description:"Web server port"`
  18. WebURL string `default:"http://localhost:8080/" description:"Web server home URL"`
  19. }
  20. func DataPath() (string, error) {
  21. dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
  22. if err != nil {
  23. return dir, err
  24. }
  25. return strings.Join(append([]string{dir}, DataDirectory), string(os.PathSeparator)), nil
  26. }
  27. func DataPathFile(filename ...string) (string, error) {
  28. dir, err := filepath.Abs(Config.DataDir)
  29. if err != nil {
  30. return dir, err
  31. }
  32. return strings.Join(append([]string{dir}, filename...), string(os.PathSeparator)), nil
  33. }