test_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log"
  6. "net/http"
  7. "testing"
  8. )
  9. func TestA(T *testing.T) {
  10. a := []int{1, 2, 3}
  11. b := a[:2]
  12. b = append(b, 4)
  13. fmt.Println(a, b) //[1 2 4],[1 2 4]
  14. b = append(b, 5)
  15. fmt.Println(a, b) //[1 2 4],[1 2 4 5]
  16. b[0] = 10
  17. fmt.Println(a, b) //[1 2 4],[10 2 4 5]
  18. }
  19. func TestB(T *testing.T) {
  20. CollArr := []string{"company_base", "company_employee", "company_history_name", "company_partner", "annual_report_base", "annual_report_website",
  21. "special_enterprise", "special_foundation", "special_gov_unit", "special_hongkong_company", "special_law_office", "special_social_organ", "special_trade_union"}
  22. for _, v := range CollArr {
  23. switch v {
  24. case "company_base":
  25. fmt.Println("company_base")
  26. case "company_employee":
  27. fmt.Println("company_employee")
  28. case "special_enterprise", "special_foundation", "special_gov_unit", "special_hongkong_company", "special_law_office", "special_social_organ", "special_trade_union":
  29. fmt.Println("special")
  30. }
  31. }
  32. }
  33. // TestGetArea 获取行政区划 城市区划代码
  34. func TestGetArea(T *testing.T) {
  35. //url := "http://xzqh.mca.gov.cn/getInfo?code=100000&type=2" //省份列表
  36. //url := "http://xzqh.mca.gov.cn/getInfo?code=100000&type=2" //省份列表
  37. //url := "http://xzqh.mca.gov.cn/data/120000_Point.geojson" //
  38. url := "http://xzqh.mca.gov.cn/data/quanguo_Point.geojson" //
  39. resp, err := http.Get(url)
  40. if err != nil {
  41. log.Printf("Error %v", err)
  42. return
  43. }
  44. defer resp.Body.Close()
  45. if resp.StatusCode != http.StatusOK {
  46. log.Printf("Error getting watcher execution status. Status code: %d", resp.StatusCode)
  47. return
  48. }
  49. var result map[string]interface{}
  50. err = json.NewDecoder(resp.Body).Decode(&result)
  51. if err != nil {
  52. log.Printf("Error decoding watcher execution result: %v", err)
  53. return
  54. }
  55. //if len(result) > 0 {
  56. // for k, _ := range result {
  57. // log.Println(k)
  58. // urlD := fmt.Sprintf("http://xzqh.mca.gov.cn/data/%s_Point.geojson", "810000")
  59. // resp, err := http.Get(urlD)
  60. // if err != nil {
  61. // log.Printf("Error %v", err)
  62. // return
  63. // }
  64. // defer resp.Body.Close()
  65. //
  66. // var resultD map[string]interface{}
  67. // err = json.NewDecoder(resp.Body).Decode(&resultD)
  68. // if err != nil {
  69. // log.Printf("Error decoding watcher execution result: %v", err)
  70. // }
  71. //
  72. // }
  73. //}
  74. //log.Println(result)
  75. }