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.

49 line
1014B

  1. package main
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "io/ioutil"
  6. "log"
  7. )
  8. //EspoCRMAPIConfig CRM configuration for API accessing
  9. type EspoCRMAPIConfig struct {
  10. //where the EspoCRM is installed
  11. BaseURL string `json:"BaseURL"`
  12. //access UserName
  13. UserName string `json:"UserName"`
  14. //access Password
  15. UserPass string `json:"UserPass"`
  16. }
  17. //CRMConfig contains secrets that cannot store in source file
  18. //
  19. var CRMConfig EspoCRMAPIConfig
  20. func readCRMConfig() error {
  21. log.Printf("read CRM config from %s\r\n", "crm_config.json")
  22. body, err := ioutil.ReadFile("crm_config.json")
  23. if err != nil {
  24. log.Fatal("Cannot read config from crm_config.json")
  25. return err
  26. }
  27. err = json.Unmarshal(body, &CRMConfig)
  28. if CRMConfig.BaseURL == "" {
  29. return errors.New("CRM BaseURL not available not available")
  30. }
  31. if CRMConfig.UserName == "" {
  32. return errors.New("CRM UserName not available not available")
  33. }
  34. if CRMConfig.UserPass == "" {
  35. return errors.New("CRM UserPass not available not available")
  36. }
  37. return err
  38. }