test_test.go 2.2 KB

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