GoLang 安装

embedded/2024/9/23 10:30:21/

golang学习笔记

goland 安装

To use Go programming language in Visual Studio Code (VSCode), you can follow these steps:

1. Install Go: Download and install the latest version of Go from the official Go website (https://golang.org/dl/).

2. Install VSCode: Download and install Visual Studio Code from the official VSCode website (https://code.visualstudio.com/download).

3. Install the Go extension for VSCode: Open VSCode and go to the Extensions view by clicking on the square icon on the left sidebar or by pressing "Ctrl+Shift+X". Search for "Go" and click on the first result, which is the official Go extension from Microsoft. Click on the "Install" button to install the extension.

4. Configure the Go extension: After installing the extension, you'll need to configure it. Open the command palette by pressing "Ctrl+Shift+P" and search for "Go: Install/Update Tools". Select it and wait for the Go tools to be installed. Once finished, open the command palette again and search for "Go: Configure Workspace Settings". Select it and choose the option "Go" to generate a default configuration file for Go in your workspace.

5. Create a new Go file: Open a new file in VSCode by clicking on "File" > "New File". Save the file with the ".go" extension, for example, "main.go".

6. Write Go code: Start writing your Go code in the new file. You'll benefit from features such as IntelliSense, code navigation, and debugging provided by the Go extension.

7. Build and run Go code: To build and run your Go code, you can use the integrated terminal in VSCode. Open the terminal by clicking on "View" > "Terminal" or pressing "Ctrl+`". In the terminal, navigate to the directory where your Go file is located using the "cd" command. Then, use the "go build" command to build your code and the "./" followed by the executable name to run your code. For example:
```
cd /path/to/your/directory
go build
./main
```

用vscode编写一个gotest.go

package mainimport "github.com/gin-gonic/gin"func main() {r := gin.Default()r.GET("/", func(c *gin.Context) {c.String(200, "Hello, Gin!")})r.Run(":8080")
}

安装vscode的插件错了

Installing github.com/ramya-rao-a/go-outline@latest FAILED
{"killed": false,"code": 1,"signal": null,"cmd": "E:\\Program Files\\Go\\bin\\go.exe install -v github.com/ramya-rao-a/go-outline@latest","stdout": "","stderr": "go: github.com/ramya-rao-a/go-outline@latest: module github.com/ramya-rao-a/go-outline: Get \"https://goproxy.io/github.com/ramya-rao-a/go-outline/@v/list\": malformed HTTP response \"\\x00\\x00\\x12\\x04\\x00\\x00\\x00\\x00\\x00\\x00\\x03\\x00\\x00\\x00\\x80\\x00\\x04\\x00\\x01\\x00\\x00\\x00\\x05\\x00\\xff\\xff\\xff\\x00\\x00\\x04\\b\\x00\\x00\\x00\\x00\\x00\\x7f\\xff\\x00\\x00\\x00\\x00\\b\\a\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01\"\n"
}1 tools failed to install.go-outline: failed to install go-outline(github.com/ramya-rao-a/go-outline@latest): Error: Command failed: E:\Program Files\Go\bin\go.exe install -v github.com/ramya-rao-a/go-outline@latest
go: github.com/ramya-rao-a/go-outline@latest: module github.com/ramya-rao-a/go-outline: Get "https://goproxy.io/github.com/ramya-rao-a/go-outline/@v/list": malformed HTTP response "\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x80\x00\x04\x00\x01\x00\x00\x00\x05\x00\xff\xff\xff\x00\x00\x04\b\x00\x00\x00\x00\x00\x7f\xff\x00\x00\x00\x00\b\a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"

解决方法

PS E:\golangwork> $env:GO111MODULE = "on"
PS E:\golangwork> $env:GOPROXY = "https://goproxy.cn"
PS E:\golangwork> go run golang.org/x/telemetry/cmd/gotelemetry@latest on
go: downloading golang.org/x/telemetry v0.0.0-20240522233618-39ace7a40ae7
go: downloading golang.org/x/sys v0.20.0
Telemetry uploading is now enabled and data will be periodically sent to https://telemetry.go.dev/. Uploaded data is used to help improve the Go toolchain and related tools, and it will be published as part of a public dataset.

查看版本

PS E:\golangwork>  go version
go version go1.22.3 windows/amd64

hello代码

package mainimport "fmt"func main() {fmt.Println("Hello, World!")
}

需要先进行go  mod init example/hello 

查看mod文件

module example/hellogo 1.22.3

进行编译

go build hello.go

运行hello.exe

PS E:\golangwork\hello> ./hello
Hello, World!

或者直接运行go run hello.go


http://www.ppmy.cn/embedded/92844.html

相关文章

av.codec.codec.UnknownCodecError: libx264

遇到 av.codec.codec.UnknownCodecError: libx264 这个错误通常意味着 PyAV 库尝试使用 libx264 编码器来编码或解码视频,但该编码器在你的系统中不可用。 libx264 是一个广泛使用的 H.264 视频编码库。如果你正在使用 PyAV 来处理视频,特别是当你尝试读…

《Redis设计与实现》读书笔记-复制

目录 1.概述 2.复制命令 3.部分重同步过程 4.部分重同步实现 4.1复制偏移量 4.2复制积压缓冲区 4.3服务器运行ID 5.总结 1.概述 在redis 通过向从服务器发送命令:SLAVE OF,让从服务器复制主服务器,成为复制。 复制的目的 让从服务器…

php怎么解决高并发的问题

处理PHP应用中的高并发问题是一个复杂的挑战,它通常涉及到多个层面的优化和策略。以下是一些常见的方法和策略,可以帮助你解决或缓解PHP应用中的高并发问题: 优化代码和数据库: - 代码优化:确保PHP代码尽可能高效&a…

element-ui表格1.0.0.1,表格的属性

前言:基于vue2element-ui的理论转实践的使用 第一组:数据显示 利用v-bind:data在table绑定数据源,将数据利用prop的属性传入到table-column,渲染到表格中 正片开始 首先,常用的属性(作者常用&#xff09…

【轨物方案】智慧供热物联网整体解决方案

目前城市供暖系统当中,供暖设备一直得不到更新和升级,没有合理的监控设备,导致对供暖的合理调控不理想,供暖严重失调而浑然不知,进而出现冷热不均的问题,极易造成资源严重浪费。缺乏成熟的管理系统&#xf…

Element-Plus组件Tree树形控件时,传输失去父节点和回显父节点下的子节点全选问题解决

使用环境 Vue 3 in Vite Element-Plus JS语法(非TS) 问题描述: 在使用Element-Plus组件Tree树形控件时,会出现如下问题: 1、子节点未全选时,往后端传输的选中节点没有包含父节点。 如下图,…

Python爬虫核心面试题2

网络爬虫 1. 什么是HTTP协议?它有哪些常见的请求方法?2. 在进行网络爬虫时,如何判断一个网站是否允许被爬取?3. 在使用HTTP请求时,如何处理重定向?4. 解释HTTP状态码200、404、500的含义。5. 什么是Session…

62_2文件上传

文件上传 ps图像上传&#xff1a;通过浏览器客户端将图片上传到服务器的磁盘上 原理 所谓的文件上传就是服务器端通过request对象获取输入流&#xff0c;将浏览器端上传的数据读取出来&#xff0c;保存到服务器端 客户端&#xff1a; 1.请求方式必须是 post 2.需要使用组件<…