当前位置:网站首页>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边栏推荐
- 【被动收入如何挣个一百万】
- The reasons why there are so many programming languages in programming internal skills
- json序列化时案例总结
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- JSON serialization case summary
- php 迷宫游戏
- 双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
- 3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
- The shortage of graphics cards finally came to an end: 3070ti for more than 4000 yuan, 2000 yuan cheaper than the original price, and 3090ti
- Flutter动态化 | Fair 2.5.0 新版本特性
猜你喜欢

Complete deep neural network CNN training with tensorflow to complete picture recognition case 2

Golang — 命令行工具cobra

SQL Injection (POST/Search)
![[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes](/img/f3/a219fe8e7438b8974d2226b4c3d4a4.png)
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
![[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

Flutter dynamic | fair 2.5.0 new version features

太阳底下无新事,元宇宙能否更上层楼?

JVM系列——概述,程序计数器day1-1

挡不住了,国产芯片再度突进,部分环节已进到4nm

MySQL functions and related cases and exercises
随机推荐
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
logback日志的整理
Screenshot of the operation steps of upload labs level 4-level 9
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
[556. Next larger element III]
Realize the recognition and training of CNN images, and process the cifar10 data set and other methods through the tensorflow framework
Resolved (error in viewing data information in machine learning) attributeerror: target_ names
Asp.Net Core1.1版本没了project.json,这样来生成跨平台包
Resource Cost Optimization Practice of R & D team
Flutter dynamic | fair 2.5.0 new version features
SwiftUI 开发经验之作为一名程序员需要掌握的五个最有力的原则
掌握Cypress命令行选项,是真正掌握Cypress的基础
Ocean CMS vulnerability - search php
R language uses the data function to obtain the sample datasets available in the current R environment: obtain all the sample datasets in the datasets package, obtain the datasets of all packages, and
Road construction issues
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
Kivy教程之 如何通过字符串方式载入kv文件设计界面(教程含源码)
【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明