You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conf.go 1.3 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package base
  5. import (
  6. "fmt"
  7. "os"
  8. "os/exec"
  9. "path"
  10. "path/filepath"
  11. "github.com/Unknwon/com"
  12. "github.com/Unknwon/goconfig"
  13. )
  14. var (
  15. AppVer string
  16. AppName string
  17. Domain string
  18. Cfg *goconfig.ConfigFile
  19. )
  20. func exeDir() (string, error) {
  21. file, err := exec.LookPath(os.Args[0])
  22. if err != nil {
  23. return "", err
  24. }
  25. p, err := filepath.Abs(file)
  26. if err != nil {
  27. return "", err
  28. }
  29. return path.Dir(p), nil
  30. }
  31. func init() {
  32. var err error
  33. workDir, err := exeDir()
  34. if err != nil {
  35. fmt.Printf("Fail to get work directory: %s\n", err)
  36. os.Exit(2)
  37. }
  38. cfgPath := filepath.Join(workDir, "conf/app.ini")
  39. Cfg, err = goconfig.LoadConfigFile(cfgPath)
  40. if err != nil {
  41. fmt.Printf("Cannot load config file '%s'\n", cfgPath)
  42. os.Exit(2)
  43. }
  44. Cfg.BlockMode = false
  45. cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
  46. if com.IsFile(cfgPath) {
  47. if err = Cfg.AppendFiles(cfgPath); err != nil {
  48. fmt.Printf("Cannot load config file '%s'\n", cfgPath)
  49. os.Exit(2)
  50. }
  51. }
  52. Cfg.BlockMode = false
  53. AppName = Cfg.MustValue("", "APP_NAME")
  54. Domain = Cfg.MustValue("server", "DOMAIN")
  55. }