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.

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