| | |
| | | package dbapi |
| | | |
| | | import ( |
| | | "basic.com/valib/deliver.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "encoding/json" |
| | | "fmt" |
| | | ) |
| | | type ReqRepClient struct {} |
| | | |
| | | type ReqrepApi struct { |
| | | |
| | | } |
| | | |
| | | const ( |
| | | ReqRep_URL = "tcp://192.168.1.11:8002" |
| | | ) |
| | | |
| | | func (api ReqrepApi)SendRequestAndGetReply(reqStr string) string { |
| | | sender := deliver.NewClient(deliver.Mode(deliver.ReqRep), ReqRep_URL) |
| | | var sendMsg = protomsg.SdkMessage{} |
| | | sendMsg.Cid = "kkkk" |
| | | byteArr, _ := json.Marshal(sendMsg) |
| | | err := sender.Send(byteArr) |
| | | if err !=nil { |
| | | fmt.Println(err) |
| | | } |
| | | |
| | | fmt.Println("SendRequest") |
| | | return "" |
| | | } |
| | | //var ReqRep_URL = "tcp://192.168.1.11:8002" |
| | | // |
| | | ////初始化rply的地址 |
| | | //func InitRplyUrl(url string) { |
| | | // ReqRep_URL = url |
| | | //} |
| | | // |
| | | //func (api ReqRepClient) DoGetRequest(url string, params map[string]string, headers map[string]string) ([]byte, error) { |
| | | // var reqBody RplyParamBody |
| | | // reqBody.Action = url |
| | | // var destMap map[string]interface{} |
| | | // for idx,val := range params { |
| | | // destMap[idx] = interface{}(val) |
| | | // } |
| | | // reqBody.Params = destMap |
| | | // return doRply(reqBody) |
| | | //} |
| | | // |
| | | //func (api ReqRepClient) DoPostRequest(url string, contentType string, body map[string]interface{}, params map[string]string, headers map[string]string) ([]byte, error) { |
| | | // var reqBody RplyParamBody |
| | | // reqBody.Action = url |
| | | // reqBody.Params = body |
| | | // return doRply(reqBody) |
| | | //} |
| | | // |
| | | //func (api ReqRepClient) DoPutRequest(url string, contentType string, body map[string]interface{}, headers map[string]string) ([]byte, error) { |
| | | // var reqBody RplyParamBody |
| | | // reqBody.Action = url |
| | | // reqBody.Params = body |
| | | // return doRply(reqBody) |
| | | //} |
| | | // |
| | | //func (api ReqRepClient) DoDeleteRequest(url string, contentType string, body map[string]interface{}, headers map[string]string) ([]byte, error) { |
| | | // var reqBody RplyParamBody |
| | | // reqBody.Action = url |
| | | // reqBody.Params = body |
| | | // return doRply(reqBody) |
| | | //} |
| | | // |
| | | //type RplyParamBody struct { |
| | | // Action string `json:"action"` //根据action判断做何种响应 |
| | | // Params map[string]interface{} `json:"params"`//参数map |
| | | //} |
| | | // |
| | | //func doRply(body RplyParamBody)([]byte,error){ |
| | | // sender := deliver.NewClient(deliver.Mode(deliver.ReqRep), ReqRep_URL) |
| | | // bytes,err := json.Marshal(body) |
| | | // if err !=nil { |
| | | // return nil,err |
| | | // } |
| | | // err = sender.Send(bytes) |
| | | // if err !=nil { |
| | | // resMsg, _ := sender.Recv() |
| | | // if resMsg !=nil { |
| | | // return resMsg,nil |
| | | // } |
| | | // } |
| | | // return nil,errors.New("nng no resp") |
| | | //} |