rpc
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.

42 lines
828 B

3 years ago
  1. package mastermsg
  2. import (
  3. "encoding/json"
  4. "github.com/golang/protobuf/proto"
  5. )
  6. func SendEventMsg(site_id, domainname, _type, memo string, data map[string]string, url ...string) (string, error) {
  7. var msg_rpc_url string = "127.0.0.1:7974"
  8. if len(url) > 0 && url[0] != "" {
  9. msg_rpc_url = url[0]
  10. }
  11. conn, _, err := DialMsgService("tcp", msg_rpc_url)
  12. if err != nil {
  13. return "", err
  14. }
  15. defer conn.Close()
  16. _data, err := json.Marshal(data)
  17. if err != nil {
  18. return "", err
  19. }
  20. req := &EventRequest{proto.String(site_id), proto.String(domainname), proto.String(_type), proto.String(memo), proto.String(string(_data)), nil}
  21. res := &EventResponse{}
  22. err = conn.SendEvent(req, res)
  23. if err != nil {
  24. return "", err
  25. }
  26. event_id := res.GetEventId()
  27. if event_id != "" {
  28. return event_id, nil
  29. }
  30. return "", nil
  31. }