当前位置:网站首页>Go: send the get request and parse the return JSON (go1.16.4)
Go: send the get request and parse the return JSON (go1.16.4)
2022-07-03 13:48:00 【Lao Liu, you are so awesome】
One ,get The way of php Code and return :
Code :
res.php
<?php
$data = [
'code'=>0,
'msg'=>'success',
'data'=>$_GET
];
echo json_encode($data);
exit;
?>return :

explain : Liu Hongdi's go The forest is a focus golang The blog of ,
Address :https://blog.csdn.net/weixin_43881017
explain : author : Liu Hongdi mailbox : [email protected]
Two ,go Code :
testController.go
// User information info
func (u *TestController) Get(c *gin.Context) {
// obtain url, Initiate request
url := "http://127.0.0.1/res.php?username=laoliu"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
// Get the result back
body, _ := ioutil.ReadAll(res.Body)
bodystr := string(body)
// For returned json Analyze the data
var dataAttr map[string]interface{}
var code string
var username string
if err := json.Unmarshal([]byte(bodystr), &dataAttr); err == nil {
for idx, value := range dataAttr {
fmt.Println(idx)
fmt.Println(value)
if (idx == "code") {
code = fmt.Sprintf("%v", value)
}
if (idx == "data") {
mapTmp := value.(map[string]interface{})
username = mapTmp["username"].(string)
}
}
} else {
fmt.Println("json Parsing error :");
fmt.Println(err.Error());
}
// return
m := map[string]interface{} {
"resCode":code,
"username":username,
}
resp := result.NewResult(c)
resp.Success(m)
}
return :

3、 ... and , see go Version of :
[email protected]:~# go version
go version go1.16.4 linux/amd64边栏推荐
- 刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?
- 物联网毕设 --(STM32f407连接云平台检测数据)
- Setting up remote links to MySQL on Linux
- Several common optimization methods matlab principle and depth analysis
- Static linked list (subscript of array instead of pointer)
- 记录关于银行回调post请求405 问题
- [today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay
- Unity EmbeddedBrowser浏览器插件事件通讯
- SQL Injection (GET/Search)
- mysql中的字段问题
猜你喜欢

刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?

SQL Injection (GET/Select)

研发团队资源成本优化实践

物联网毕设 --(STM32f407连接云平台检测数据)

Logback log sorting

Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
![[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered

又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了

Logseq evaluation: advantages, disadvantages, evaluation, learning tutorial

PowerPoint tutorial, how to save a presentation as a video in PowerPoint?
随机推荐
树的深入和广度优先遍历(不考虑二叉树)
SQL Injection (POST/Select)
Today's sleep quality record 77 points
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
PhpMyAdmin stage file contains analysis traceability
刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?
pytorch 载入历史模型时更换gpu卡号,map_location设置
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Golang — template
【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
挡不住了,国产芯片再度突进,部分环节已进到4nm
CVPR 2022 | 美团技术团队精选6篇优秀论文解读
使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
Field problems in MySQL