consts.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. Deployment string `default:"development" description:"Deployment type"`
  13. ErrorLogFile string `description:"Error log file"`
  14. Host string `default:"127.0.0.1" description:"Web server IP"`
  15. Port string `default:"8080" description:"Web server port"`
  16. WebURL string `default:"http://localhost:8080/" description:"Web server home URL"`
  17. }
  18. func DataPath() (string, error) {
  19. dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
  20. if err != nil {
  21. return dir, err
  22. }
  23. return strings.Join(append([]string{dir}, DataDirectory), string(os.PathSeparator)), nil
  24. }
  25. func DataPathFile(filename ...string) (string, error) {
  26. dir, err := filepath.Abs(Config.DataDir)
  27. if err != nil {
  28. return dir, err
  29. }
  30. return strings.Join(append([]string{dir}, filename...), string(os.PathSeparator)), nil
  31. }