您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

80 行
1.7KB

  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. //where attachment is cached
  17. AttachmentCache string `json:"AttachmentCache"`
  18. //where cache site is provding attachment access
  19. //temporary
  20. CacheSiteURL string `json:"CacheSiteURL"`
  21. }
  22. //CRMConfig contains secrets that cannot store in source file
  23. //
  24. var CRMConfig EspoCRMAPIConfig
  25. func readCRMConfig() error {
  26. log.Printf("read CRM config from %s\r\n", "crm_config.json")
  27. body, err := ioutil.ReadFile("crm_config.json")
  28. if err != nil {
  29. log.Fatal("Cannot read config from crm_config.json")
  30. return err
  31. }
  32. err = json.Unmarshal(body, &CRMConfig)
  33. if CRMConfig.BaseURL == "" {
  34. return errors.New("CRM BaseURL not available not available")
  35. }
  36. if CRMConfig.UserName == "" {
  37. return errors.New("CRM UserName not available not available")
  38. }
  39. if CRMConfig.UserPass == "" {
  40. return errors.New("CRM UserPass not available not available")
  41. }
  42. return err
  43. }
  44. func (c EspoCRMAPIConfig) apiURL(entityType string) string {
  45. return c.BaseURL + "api/v1/" + entityType
  46. }
  47. func (c EspoCRMAPIConfig) apiEntityURL(entityType, id string) string {
  48. return c.apiURL(entityType) + "/" + id
  49. }
  50. func (c EspoCRMAPIConfig) apiLeadURL() string {
  51. return c.apiURL("Lead")
  52. }
  53. func (c EspoCRMAPIConfig) apiAuthURL() string {
  54. return c.apiURL("App/user")
  55. }
  56. func (c EspoCRMAPIConfig) apiUploadAttachmentURL() string {
  57. return c.apiURL("Attachment/action/upload")
  58. }
  59. func (c EspoCRMAPIConfig) apiConvertLeadURL() string {
  60. return c.apiURL("Lead/action/convert")
  61. }