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 Spring Boot设置RestTemplate的超时时间
Spring Boot设置RestTemplate的超时时间
2
Magento 2日志打印
Magento 2日志打印
3
Vue2.0 watch选项 handler deep immediate
Vue2.0 watch选项 handler deep immediate
4
Win64安装MySQL-python
Win64安装MySQL-python
5
OKHttp3学习之六:文件下载(简单方式)
OKHttp3学习之六:文件下载(简单方式)
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。