Gin 系列讲座: Saas系统, Gin+Jwt+casbin RestFul Api 后端一战到底 0: Go开发环境安装

Gin 系列讲座: Saas系统, Gin+Jwt+casbin RestFul Api 后端一战到底

0. Go开发环境安装

目的

本文目的是一个地方,学会完整的全栈开发,搞定后端部分, 后续若是反响好,会吧把前端部分也补充前端

国内下载地址

当前版本: 1.13.4linux

go modules

主意go 1.13之后官方默认支持模块方式,因此咱们不在介绍哦以前的使用GOPATH的方式. 拥抱模块吧.git

(本文介绍ubuntu上安装)

下载安装包 dl.google.com/go/go1.13.4… -若是是windows系统建议下载virtualbox 虚拟机在按照github

下载解压

wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz

tar -zxvf go1.9.2.linux-amd64.tar.gz

mv go/ /usr/local/
复制代码

环境变量

配置 /etc/profile

vi /etc/profile
添加环境变量GOROOT和将GOBIN添加到PATH中

export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
复制代码

配置完毕后,执行命令令其生效golang

source /etc/profile
复制代码

在控制台输入go version,若输出版本号则安装成功ubuntu

执行 go help命令查看帮助windows

go help                                                                               ✔  10109  20:09:08 
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         download and install packages and dependencies
	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.
复制代码

恭喜,你已经成功安装go, 接下来能够开发了.

注意,咱们特地不设置GOPATH命令 后面的开发都已模块方式开发,抛弃老的Gopath方式.

请不要太在乎模块. 慢慢的你就会理解.后端

安装Gin

在命令行下执行安装bash

go get -u github.com/gin-gonic/gin
检查/usr/local/go/path中是否存在gin的代码包
复制代码

测试Gin是否安装成功

编写一个test.go文件curl

package main

import "github.com/gin-gonic/gin"

func main() {
    r := gin.Default()
    r.GET("/ping", func(c *gin.Context) {
        c.JSON(200, gin.H{
            "message": "pong",
        })
    })
    r.Run() // listen and serve on 0.0.0.0:8080
}
复制代码

执行test.go

go run test.go
复制代码

访问$HOST:8080/ping,若返回{"message":"pong"}则正确

curl 127.0.0.1:8080/ping
复制代码

至此,咱们的环境安装都基本完成了 :)

上面只是一个Gin的小Demo .感觉一下从无到个哦按照开发

相关文章
相关标签/搜索