代码如下:

  1. func createService() {
  2. client := &http.Client{}
  3. nonce := RandString(10)
  4. timestamp := fmt.Sprintf("%v", time.Now().Unix())
  5. router := make(map[string]interface{})
  6. postData := make(map[string]interface{})
  7. targetHosts := []string{"rio.shaohualee.com"}
  8. router["pubHost"] = "rio.shaohualee.com"
  9. router["pubPath"] = "/ebus/lee/lish"
  10. postData["paasid"] = "lee"
  11. postData["description"] = "app1_sr1_lish"
  12. postData["isPublic"] = true
  13. postData["router"] = router
  14. bytesData, _ := json.Marshal(postData)
  15. reader := bytes.NewReader(bytesData)
  16. request, _ := http.NewRequest("POST", baseUrl+"/ebus/amp/app/service/create?version=2018-12-18", reader)
  17. secret := "K2pRkyqRVaMNTy8O4bblaXpaoTeGnVTm"
  18. request.Header.Add("x-tif-paasid", "amp")
  19. request.Header.Add("x-tif-timestamp", timestamp)
  20. request.Header.Add("x-tif-nonce", nonce)
  21. request.Header.Add("x-tif-signature", getSign(nonce, secret, timestamp))
  22. request.Header.Add("content-type", "application/json; charset=utf-8")
  23. request.Header.Add("user-agent", "tif.SgUtil")
  24. //接收服务端返回给客户端的信息
  25. res, _ := client.Do(request)
  26. if res != nil && res.StatusCode == 200 {
  27. str, _ := ioutil.ReadAll(res.Body)
  28. bodyStr := string(str)
  29. fmt.Println(bodyStr)
  30. }
  31. }

分类: web

标签:   golang