windows平台国内Go语言环境的搭建以及Gin框架的安装

简介: gin环境配置经验贴,在国内网络环境下通过国内代理服务器完成go环境配置

Go的安装

首先需要在官网Golang.google.cn下载.msi 后缀(在下载列表中可以找到该文件,如go1.4.2.windows-amd64.msi)的安装包来安装。

默认情况下 .msi 文件会安装在 c:\Go 目录下。你可以将 c:\Go\bin 目录添加到 Path 环境变量中。添加后你需要重启命令窗口才能生效。

安装成功后在命令行窗口执行命令

go

将会出现go的命令信息

Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         add dependencies to current module and install them
        install     compile and install packages and dependencies
        list        list packages or modules
        mod         module maintenance
        run         compile and run Go program
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

        buildmode   build modes
        c           calling between Go and C
        cache       build and test caching
        environment environment variables
        filetype    file types
        go.mod      the go.mod file
        gopath      GOPATH environment variable
        gopath-get  legacy GOPATH go get
        goproxy     module proxy protocol
        importpath  import path syntax
        modules     modules, module versions, and more
        module-get  module-aware go get
        module-auth module authentication using go.sum
        module-private module configuration for non-public modules
        packages    package lists and patterns
        testflag    testing flags
        testfunc    testing functions

Use "go help <topic>" for more information about that topic.

环境变量GO111MODULE的修改

在安装第三方包的时候,由于网络问题golang.org在国内无法正常使用,导致我们无法使用第三方包管理工具,因此可以通过修改系统环境变量将golang.org切换至国内CDN。

windows下,执行如下命令

$env:GO111MODULE="on" 

go.mod是一个go项目的依赖管理文件,关于go.mod的问题此处不再拓展,这里面GO111MODULE的参数是这是项目与go.mod的关系,可选 auto onoffauto 根据是否在 src 下自动判定, on 只用 go.mod , off 只用 src,此处参数on可以设置为on或者auto

国内CDN的切换

可以通过设定GOPROXY环境变量来实现国内CDN的切换,可以通过执行下面任一命令切换至七牛云,阿里云或是官方

$env:GOPROXY="https://goproxy.cn,direct"   #七牛云
$env:GOPROXY="https://mirrors.aliyun.com/goproxy/,direct"   #阿里云
$env:GOPROXY="https://goproxy.io,direct"  #官方

Gin的安装

执行命令来完成Gin的安装

go get -u -v github.com/gin-gonic/gin
目录
相关文章
|
1月前
|
测试技术 API 开发者
【Docker项目实战】在Docker环境下部署go-file文件分享工具
【2月更文挑战第15天】在Docker环境下部署go-file文件分享工具
67 1
|
2月前
|
中间件 Go 数据库
Go开发者必读:Gin框架的实战技巧与最佳实践
在当今快速发展的互联网时代,Web开发的需求日益增长。Go语言以其简洁、高效、并发性强的特点,成为了开发者们的首选。而在Go语言的众多Web框架中,Gin无疑是其中的佼佼者。本文将深入探讨Gin框架的特性、优势以及如何利用Gin构建高性能的Web应用。
|
5月前
|
Go Windows
Go 交叉编译 跨平台编译(windows系统跨平台编译)
Go 交叉编译 跨平台编译(windows系统跨平台编译)
32 0
|
1月前
|
测试技术 Go 云计算
Go语言优化云计算与容器化环境的策略与最佳实践
【2月更文挑战第15天】在云计算和容器化环境中,Go语言的应用和优化策略对于提高系统的性能和效率至关重要。本文深入探讨了如何使用Go语言优化云计算和容器化环境,包括内存管理、并发编程、代码优化等方面的最佳实践,旨在帮助开发者充分利用Go语言的优势,提升系统的整体性能。
|
1月前
|
Kubernetes Go 开发者
Go语言在容器化环境中的实践
【2月更文挑战第15天】随着容器技术的兴起,Go语言在容器化环境中的实践逐渐受到关注。本文探讨了Go语言如何与容器技术相结合,发挥其在容器化环境中的优势,包括轻量级部署、高并发处理、快速构建和部署等方面的特点,并通过实例展示了Go语言在容器化环境中的实践应用。
|
1月前
|
Go 开发工具 Windows
【GO语言】windows下GO语言环境搭建
【2月更文挑战第1天】windows下GO语言环境搭建
|
2月前
|
Unix Linux Go
开心档之 Go 语言环境安装
开心档之 Go 语言环境安装
|
3月前
|
关系型数据库 MySQL Go
go语言使用Gin框架链接数据库
go语言使用Gin框架链接数据库
40 0
|
3月前
|
Linux Go
Centos 7安装Go语言环境
Centos 7安装Go语言环境
22 0
|
3月前
|
JavaScript 前端开发 NoSQL
go embed 实现gin + vue静态资源嵌入
go embed 实现gin + vue静态资源嵌入
64 0