当前位置:网站首页>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边栏推荐
- Anan's doubts
- Libuv Library - Design Overview (Chinese version)
- JS 将伪数组转换成数组
- PowerPoint tutorial, how to save a presentation as a video in PowerPoint?
- 8皇后问题
- Error running 'application' in idea running: the solution of command line is too long
- NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
- Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
- MySQL installation, uninstallation, initial password setting and general commands of Linux
- The principle of human voice transformer
猜你喜欢
![[技術發展-24]:現有物聯網通信技術特點](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[技術發展-24]:現有物聯網通信技術特點

This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version

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

Setting up remote links to MySQL on Linux

There is nothing new under the sun. Can the meta universe go higher?

Mycms we media mall v3.4.1 release, user manual update
![[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心

Logseq evaluation: advantages, disadvantages, evaluation, learning tutorial
![[redis] cache warm-up, cache avalanche and cache breakdown](/img/df/81f38087704de36946b470f68e8004.jpg)
[redis] cache warm-up, cache avalanche and cache breakdown

Universal dividend source code, supports the dividend of any B on the BSC
随机推荐
106. How to improve the readability of SAP ui5 application routing URL
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
SQL Injection (GET/Search)
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
【被动收入如何挣个一百万】
软件测试工作那么难找,只有外包offer,我该去么?
mysql中的字段问题
Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
常见的几种最优化方法Matlab原理和深度分析
Spark practice 1: build spark operation environment in single node local mode
Internet of things completion -- (stm32f407 connects to cloud platform detection data)
User and group command exercises
Today's sleep quality record 77 points
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
Unity embeddedbrowser browser plug-in event communication
Flutter动态化 | Fair 2.5.0 新版本特性
[technology development-24]: characteristics of existing IOT communication technology
The network card fails to start after the cold migration of the server hard disk
Introduction to the implementation principle of rxjs observable filter operator