|
|
- package mastermsg
-
- import (
- "encoding/json"
-
- "github.com/golang/protobuf/proto"
- )
-
- func SendEventMsg(site_id, domainname, _type, memo string, data map[string]string, url ...string) (string, error) {
-
- var msg_rpc_url string = "127.0.0.1:7974"
- if len(url) > 0 && url[0] != "" {
- msg_rpc_url = url[0]
- }
- conn, _, err := DialMsgService("tcp", msg_rpc_url)
- if err != nil {
- return "", err
- }
- defer conn.Close()
-
- _data, err := json.Marshal(data)
- if err != nil {
- return "", err
- }
-
- req := &EventRequest{proto.String(site_id), proto.String(domainname), proto.String(_type), proto.String(memo), proto.String(string(_data)), nil}
-
- res := &EventResponse{}
-
- err = conn.SendEvent(req, res)
-
- if err != nil {
- return "", err
- }
-
- event_id := res.GetEventId()
- if event_id != "" {
- return event_id, nil
- }
-
- return "", nil
- }
|