Guest User

Untitled

a guest
Apr 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. config/config.go
  2. @@ -96,6 +96,7 @@ type Config struct {
  3.  
  4. EMail SMTPConf
  5. Slack SlackConf
  6. // config追加
  7. + HipChat HipChatConf
  8. Syslog SyslogConf
  9. Default ServerInfo
  10. Servers map[string]ServerInfo
  11. @@ -263,6 +264,10 @@ func (c Config) ValidateOnReport() bool {
  12. errs = append(errs, slackerrs...)
  13. }
  14.  
  15. // 確かconfig validate的なコマンドがあって、hipchatのconfig validateも呼ぶように追加
  16. // そんなコマンドはないかも。ただ-to-hipchatオプションを付けたのにhipchatの設定がない場合
  17. // エラーが出ると思うので、そのへんの処理。
  18. + if hipchaterrs := c.HipChat.Validate(); 0 < len(hipchaterrs) {
  19. + errs = append(errs, hipchaterrs...)
  20. + }
  21. +
  22. if syslogerrs := c.Syslog.Validate(); 0 < len(syslogerrs) {
  23. errs = append(errs, syslogerrs...)
  24. }
  25. @@ -451,6 +456,30 @@ func (c *SlackConf) Validate() (errs []error) {
  26. return
  27. }
  28.  
  29. // tomlのhip chat configを受け取る構造体
  30. +// HipChatConf is HipChat config
  31. +type HipChatConf struct {
  32. + AuthToken string `json:"AuthToken"`
  33. + Room string `json:"Room"`
  34. +}
  35. +
  36. // configのvalidate処理
  37. +// Validate validates configuration
  38. +func (c *HipChatConf) Validate() (errs []error) {
  39. + if len(c.Room) == 0 {
  40. + errs = append(errs, fmt.Errorf("room must not be empty"))
  41. + }
  42. +
  43. + if len(c.AuthToken) == 0 {
  44. + errs = append(errs, fmt.Errorf("AuthToken must not be empty"))
  45. + }
  46. +
  47. + _, err := valid.ValidateStruct(c)
  48. + if err != nil {
  49. + errs = append(errs, err)
  50. + }
  51. +
  52. + return
  53. +}
  54. +
  55. // SyslogConf is syslog config
  56. type SyslogConf struct {
  57. Protocol string
Add Comment
Please, Sign In to add comment