当前位置:网站首页>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边栏推荐
- [technology development-24]: characteristics of existing IOT communication technology
- [机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
- IBEM 数学公式检测数据集
- PowerPoint tutorial, how to save a presentation as a video in PowerPoint?
- Anan's doubts
- The shadow of the object at the edge of the untiy world flickers, and the shadow of the object near the far point is normal
- 双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
- Windos creates Cordova prompt because running scripts is prohibited on this system
- Libuv库 - 设计概述(中文版)
- Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
猜你喜欢

NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线

TensorBoard可视化处理案例简析

3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)

SQL Injection (AJAX/JSON/jQuery)

Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station

AI 考高数得分 81,网友:AI 模型也免不了“内卷”!

Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm

Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.

双向链表(我们只需要关注插入和删除函数)
![[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update](/img/b8/31609303fd817c48b6fff7c43f31e5.png)
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
随机推荐
PhpMyAdmin stage file contains analysis traceability
Unity embeddedbrowser browser plug-in event communication
windos 创建cordova 提示 因为在此系统上禁止运行脚本
When updating mysql, the condition is a query
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
Kivy教程之 如何通过字符串方式载入kv文件设计界面(教程含源码)
双向链表(我们只需要关注插入和删除函数)
记录关于银行回调post请求405 问题
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
Libuv Library - Design Overview (Chinese version)
Record 405 questions about bank callback post request
JS 将伪数组转换成数组
Ubuntu 14.04 下开启PHP错误提示
Several common optimization methods matlab principle and depth analysis
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
Error running 'application' in idea running: the solution of command line is too long
Mycms we media mall v3.4.1 release, user manual update
Stack application (balancer)
Road construction issues
Halcon combined with C # to detect surface defects -- Halcon routine autobahn