当前位置: 首页 > news >正文

GoLang 安装

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

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 导出easyExcel(前端vue2/后端springboot)
  • Java 面试常见问题之——为什么重写equals时必须重写hashCode方法
  • thinkphp框架远程代码执行
  • MATLAB在算法处理上的作用
  • 鸿蒙系统学习指南
  • 学习大数据DAY30 python基础语法3
  • 渗透测试--DNS劫持实验
  • 5.0-软件工程基础知识-考点分析
  • 自用git命令(待完善)
  • 前端开源插件
  • 如何用Java编写Kafka生产者代码,实现定时向Kafka集群发送批量数据的功能?
  • 防御笔记第九天(持续更新)
  • C# 6.定时器 timer
  • linux系统编程中Shell脚本配置,及linux脚本中的man test
  • 【数据结构与算法】单链表、双链表和循环单链表中头指针未知的情况下能否删除某节点
  • 【React系列】如何构建React应用程序
  • 30秒的PHP代码片段(1)数组 - Array
  • CentOS7 安装JDK
  • Laravel5.4 Queues队列学习
  • LintCode 31. partitionArray 数组划分
  • maya建模与骨骼动画快速实现人工鱼
  • MySQL数据库运维之数据恢复
  • OSS Web直传 (文件图片)
  • Vue.js-Day01
  • 阿里研究院入选中国企业智库系统影响力榜
  • 不用申请服务号就可以开发微信支付/支付宝/QQ钱包支付!附:直接可用的代码+demo...
  • 动态规划入门(以爬楼梯为例)
  • 发布国内首个无服务器容器服务,运维效率从未如此高效
  • 微信小程序开发问题汇总
  • 为物联网而生:高性能时间序列数据库HiTSDB商业化首发!
  • 限制Java线程池运行线程以及等待线程数量的策略
  • 小程序开发之路(一)
  • 一些基于React、Vue、Node.js、MongoDB技术栈的实践项目
  • C# - 为值类型重定义相等性
  • 积累各种好的链接
  • ​HTTP与HTTPS:网络通信的安全卫士
  • ​secrets --- 生成管理密码的安全随机数​
  • # 飞书APP集成平台-数字化落地
  • #Datawhale AI夏令营第4期#AIGC文生图方向复盘
  • #Linux(权限管理)
  • (22)C#传智:复习,多态虚方法抽象类接口,静态类,String与StringBuilder,集合泛型List与Dictionary,文件类,结构与类的区别
  • (8)Linux使用C语言读取proc/stat等cpu使用数据
  • (function(){})()的分步解析
  • (Python第六天)文件处理
  • (第61天)多租户架构(CDB/PDB)
  • (含react-draggable库以及相关BUG如何解决)固定在左上方某盒子内(如按钮)添加可拖动功能,使用react hook语法实现
  • (六)Hibernate的二级缓存
  • (欧拉)openEuler系统添加网卡文件配置流程、(欧拉)openEuler系统手动配置ipv6地址流程、(欧拉)openEuler系统网络管理说明
  • (一) storm的集群安装与配置
  • .bat批处理(二):%0 %1——给批处理脚本传递参数
  • .Net Attribute详解(上)-Attribute本质以及一个简单示例
  • .NET Core中如何集成RabbitMQ
  • .net web项目 调用webService
  • .NET 程序如何获取图片的宽高(框架自带多种方法的不同性能)
  • .NET应用架构设计:原则、模式与实践 目录预览