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 satır
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. TlsCert string
  17. TlsKey string
  18. Static []configStaticHtml
  19. Debug bool
  20. Session struct { //TODO: figure what is this intended for
  21. Guest bool
  22. Year int //how many years
  23. Month int //how many years
  24. Day int //how many years
  25. }
  26. }
  27. var configFile = "config.json"
  28. var config = configuration{}
  29. func (m *configuration) readConfig() (e error) {
  30. log.Printf("read Path config from %s", configFile)
  31. body, e := ioutil.ReadFile(configFile)
  32. if e != nil {
  33. log.Fatal("Cannot read config from " + configFile)
  34. return
  35. }
  36. e = json.Unmarshal(body, m)
  37. //TODO: check config before proceed further
  38. return
  39. }
  40. func (m *configuration) getAvatarPath() (ret string) {
  41. for _, v := range m.Static {
  42. if strings.ToLower(v.Dir) == "avatar" {
  43. return v.Dir //found it
  44. }
  45. }
  46. return ""
  47. }