選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

71 行
1.5KB

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