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.9 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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. "github.com/gogits/gogs/modules/log"
  14. )
  15. // Mailer represents a mail service.
  16. type Mailer struct {
  17. Name string
  18. Host string
  19. User, Passwd string
  20. }
  21. var (
  22. AppVer string
  23. AppName string
  24. Domain string
  25. Cfg *goconfig.ConfigFile
  26. MailService *Mailer
  27. )
  28. func exeDir() (string, error) {
  29. file, err := exec.LookPath(os.Args[0])
  30. if err != nil {
  31. return "", err
  32. }
  33. p, err := filepath.Abs(file)
  34. if err != nil {
  35. return "", err
  36. }
  37. return path.Dir(p), nil
  38. }
  39. func init() {
  40. var err error
  41. workDir, err := exeDir()
  42. if err != nil {
  43. fmt.Printf("Fail to get work directory: %s\n", err)
  44. os.Exit(2)
  45. }
  46. cfgPath := filepath.Join(workDir, "conf/app.ini")
  47. Cfg, err = goconfig.LoadConfigFile(cfgPath)
  48. if err != nil {
  49. fmt.Printf("Cannot load config file '%s'\n", cfgPath)
  50. os.Exit(2)
  51. }
  52. Cfg.BlockMode = false
  53. cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
  54. if com.IsFile(cfgPath) {
  55. if err = Cfg.AppendFiles(cfgPath); err != nil {
  56. fmt.Printf("Cannot load config file '%s'\n", cfgPath)
  57. os.Exit(2)
  58. }
  59. }
  60. Cfg.BlockMode = false
  61. AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
  62. Domain = Cfg.MustValue("server", "DOMAIN")
  63. // Check mailer setting.
  64. if Cfg.MustBool("mailer", "ENABLED") {
  65. MailService = &Mailer{
  66. Name: Cfg.MustValue("mailer", "NAME", AppName),
  67. Host: Cfg.MustValue("mailer", "HOST", "127.0.0.1:25"),
  68. User: Cfg.MustValue("mailer", "USER", "example@example.com"),
  69. Passwd: Cfg.MustValue("mailer", "PASSWD", "******"),
  70. }
  71. log.Info("Mail Service Enabled")
  72. }
  73. }