Created
October 18, 2019 15:21
-
-
Save jeffotoni/c5eed232eb0c5d6428320c5088c783d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
func UploadPost1(uqueue mfqueue.Queue) (*MessageJson, bool, string) { | |
var mJson = MessageJson{} | |
//u := User{Id: "US123", Balance: 8} | |
b := new(bytes.Buffer) | |
json.NewEncoder(b).Encode(uqueue) | |
res, err := http.Post("http://apiphp.projeto1.local/apiphp/sqs/queue", "application/json; charset=utf-8", b) | |
if err != nil { | |
mJson.Status = "error" | |
mJson.Msg = util.Concat(`{"msg":"Erro client.Do three: `, err.Error(), `}`) | |
return &mJson, false, mJson.Msg | |
} | |
io.Copy(os.Stdout, res.Body) | |
mJson.Status = "test" | |
mJson.Msg = "testando send post golang" | |
return &mJson, false, util.Concat(`{"msg":"Erro client.Do Two: `, mJson.Msg, `}`) | |
} | |
func UploadPos2(uqueue mfqueue.Queue) (*MessageJson, bool, string) { | |
var mJson = MessageJson{} | |
url := "http://localhost:8282" | |
fmt.Println("URL:>", url) | |
request := gorequest.New() | |
//titleList := []string{"title1", "title2", "title3"} | |
//for _, title := range titleList { | |
resp, body, errs := request.Post(url). | |
Set("X-Custom-Header", "myvalue"). | |
Send(`{"title":"enviando um teste jeffotoni!"}`). | |
End() | |
if errs != nil { | |
mJson.Status = "error" | |
mJson.Msg = util.Concat(`{"msg":"Erro client.Do three: `, errs, `}`) | |
return &mJson, false, mJson.Msg | |
} | |
fmt.Println("response Status:", resp.Status) | |
fmt.Println("response Headers:", resp.Header) | |
fmt.Println("response Body:", body) | |
return &mJson, true, string(body) | |
//} | |
} | |
func UploadPost3(uqueue mfqueue.Queue) (*MessageJson, bool, string) { | |
// struct return json | |
var mJson = MessageJson{} | |
url := "http://localhost:8282" | |
fmt.Println("URL:>", url) | |
var jsonStr = []byte(`{"title":"Buy cheese and bread for breakfast jeffotoni!"}`) | |
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) | |
req.Header.Set("X-Custom-Header", "myvalue") | |
req.Header.Set("Content-Type", "application/json") | |
client := &http.Client{} | |
resp, err := client.Do(req) | |
if err != nil { | |
fmt.Println(err) | |
mJson.Status = "error" | |
mJson.Msg = util.Concat(`{"msg":"Erro client.Do Two: `, err.Error(), `}`) | |
return &mJson, false, mJson.Msg | |
} | |
defer resp.Body.Close() | |
fmt.Println("response Status:", resp.Status) | |
fmt.Println("response Headers:", resp.Header) | |
body, _ := ioutil.ReadAll(resp.Body) | |
fmt.Println("response Body:", string(body)) | |
return &mJson, true, string(body) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment