Windows下安装golang

官方下载:https://golang.google.cn/dl/
推荐下载:go1.20.12

# go version
go version go1.20.12 windows/amd64

# set GOPROXY=https://goproxy.cn

IDEA配置

插件安装:Go

IDEA GOPATH配置:

Settings -> Languages & Frameworks -> Go -> GOPATH

IDEA golang开启mod后import报红解决方案:

Settings -> Languages & Frameworks -> Go -> Go Modules (vgo) -> 勾选 Enable Go Modules (vgo) integration

测试

# vim json.go
# go mod init appblog.cn/go-test/v2
go: creating new go.mod: module appblog.cn/go-test/v2
go: to add module requirements and sums:
        go mod tidy

# go install

# go run json.go
{"nested":{"field":"value"}}
package main

import (
    "encoding/json"
    "fmt"
)

type InnerStruct struct {
    Field string json:"field" // 内部JSON对象的字段名为 "field"
}

type OuterStruct struct {
    Nested InnerStruct json:"nested" // 外部JSON对象的字段名为 "nested"
}

func main() {
    inner := InnerStruct{Field: "value"} // 初始化内部JSON对象
    outer := OuterStruct{}               // 初始化外部JSON对象

    // 将内部JSON对象赋值给外部JSON对象的字段
    outer.Nested = inner

    // 将外部JSON对象转换成JSON格式的字符串
    result, err := json.Marshal(outer)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(result))
}
上一篇 Groovy代码示例 - 如何为groovy脚本编译后的class文件指定名字?
下一篇 go项目开发时,报cc1.exe: sorry, unimplemented: 64-bit mode not compiled in解决办法
目录
文章列表
1 Called attach on a child which is not detached ViewHolder问题解决
Called attach on a child which is not detached ViewHolder问题解决
2
JS处理数据四舍五入tofixed与round的区别
JS处理数据四舍五入tofixed与round的区别
3
Executors提供四种线程池
Executors提供四种线程池
4
Python搭建HTTP服务器:Windows下使用virtualenv安装Flask
Python搭建HTTP服务器:Windows下使用virtualenv安装Flask
5
MySQL 排序
MySQL 排序
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。