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.

57 lines
1.0KB

  1. package main
  2. import (
  3. "encoding/json"
  4. log "github.com/sirupsen/logrus"
  5. "io/ioutil"
  6. "strings"
  7. )
  8. type configStaticHtml struct {
  9. Dir string
  10. StaticUrl string
  11. StripPrefix string
  12. }
  13. type configuration struct {
  14. Host string
  15. Port string
  16. DSN string
  17. TlsCert string
  18. TlsKey string
  19. Static []configStaticHtml
  20. Debug bool
  21. Uploads string
  22. Session struct { //TODO: figure what is this intended for
  23. Guest bool
  24. Year int //how many years
  25. Month int //how many years
  26. Day int //how many years
  27. }
  28. }
  29. var configFile = "config.json"
  30. var config = configuration{}
  31. func (m *configuration) readConfig() (e error) {
  32. log.Printf("read Path config from %s", configFile)
  33. body, e := ioutil.ReadFile(configFile)
  34. if e != nil {
  35. log.Fatal("Cannot read config from " + configFile)
  36. return
  37. }
  38. e = json.Unmarshal(body, m)
  39. //TODO: check config before proceed further
  40. return
  41. }
  42. func (m *configuration) getAvatarPath() (ret string) {
  43. for _, v := range m.Static {
  44. if strings.ToLower(v.Dir) == "avatar" {
  45. return v.Dir //found it
  46. }
  47. }
  48. return ""
  49. }