projects_test.go 877 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package api_v1
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. "log"
  6. "net/http"
  7. "strings"
  8. "testing"
  9. )
  10. func init() {
  11. //todo init connection db operation
  12. }
  13. func Test_ProjectDetails(t *testing.T) {
  14. data := post("http://127.0.0.1:8080/sfis/api/v1/projectDetail", map[string]string{
  15. "id": "5f6b4e12499cb0822d39c68f",
  16. })
  17. res := map[string]interface{}{}
  18. s, _ := json.Marshal(data)
  19. json.Unmarshal(s, &res)
  20. log.Println("数据:", res)
  21. }
  22. func post(url string, form map[string]string) (data map[string]interface{}) {
  23. str := ""
  24. for k, v := range form {
  25. str += "&" + k + "=" + v
  26. }
  27. log.Println(str)
  28. res, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(str))
  29. if err != nil {
  30. log.Println("post err:", err.Error())
  31. } else if res.Body != nil {
  32. defer res.Body.Close()
  33. bs, _ := ioutil.ReadAll(res.Body)
  34. json.Unmarshal(bs, &data)
  35. }
  36. return
  37. }