push.go 775 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package configs
  2. import (
  3. "crm-api/pkg/lfshook"
  4. "encoding/json"
  5. "io/ioutil"
  6. )
  7. type PushConfig struct {
  8. AMIEvents []string `json:"events"`
  9. AMIPushUrl string `json:"allEventPushUrl"`
  10. }
  11. var PushConfigValue PushConfig
  12. func GetPushConfig() {
  13. data, err := ioutil.ReadFile(ConfigGlobal.PushConfig)
  14. if err != nil {
  15. PushConfigValue = PushConfig{
  16. AMIEvents: []string{},
  17. AMIPushUrl: "",
  18. }
  19. return
  20. }
  21. json.Unmarshal(data, &PushConfigValue)
  22. }
  23. func UpdatePushConfig(config PushConfig) error {
  24. event, err := json.Marshal(config)
  25. if err != nil {
  26. lfshook.NewLogger().Error(err)
  27. return err
  28. }
  29. err = ioutil.WriteFile(ConfigGlobal.PushConfig, event, 666)
  30. if err != nil {
  31. lfshook.NewLogger().Error(err)
  32. return err
  33. }
  34. PushConfigValue = config
  35. return nil
  36. }