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

55 lines
1.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  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 Cfg *goconfig.ConfigFile
  15. func exeDir() (string, error) {
  16. file, err := exec.LookPath(os.Args[0])
  17. if err != nil {
  18. return "", err
  19. }
  20. p, err := filepath.Abs(file)
  21. if err != nil {
  22. return "", err
  23. }
  24. return path.Dir(p), nil
  25. }
  26. func init() {
  27. var err error
  28. workDir, err := exeDir()
  29. if err != nil {
  30. fmt.Printf("Fail to get work directory: %s\n", err)
  31. os.Exit(2)
  32. }
  33. cfgPath := filepath.Join(workDir, "conf/app.ini")
  34. Cfg, err = goconfig.LoadConfigFile(cfgPath)
  35. if err != nil {
  36. fmt.Printf("Cannot load config file '%s'\n", cfgPath)
  37. os.Exit(2)
  38. }
  39. cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
  40. if com.IsFile(cfgPath) {
  41. if err = Cfg.AppendFiles(cfgPath); err != nil {
  42. fmt.Printf("Cannot load config file '%s'\n", cfgPath)
  43. os.Exit(2)
  44. }
  45. }
  46. Cfg.BlockMode = false
  47. }