Gin Series: Saas System, Gin+Jwt+ Casbin RestFul Api backend battle to the end

0. Install Go development environment

purpose

The purpose of this article is a place, learn to complete the full stack development, fix the back-end part, if the follow-up response is good, will put the front-end part also supplement

Home Download address

  • Official website address (can be accessed directly) golang.org/
  • For those who cannot visit, please visit golang.google.cn/dl/

Current version: 1.13.4

go modules

The idea is that after Go 1.13, the official default support module mode, so we will not cover the way to use GOPATH before. Embrace modules.

(This article describes installing on Ubuntu.)

Download the installation package dl.google.com/go/go1.13.4… – If the VM runs Windows, you are advised to download VirtualBox

Download decompression

Wget https://dl.google.com/go/go1.13.4.linux-amd64.tar.gz tar - ZXVF go1.9.2. Linux - amd64. Tar. Gz go / / usr/mvlocal/
Copy the code

The environment variable

Configure /etc/profile vi /etc/profile Add environment variable GOROOT and add GOBIN to PATHexport GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
Copy the code

After the configuration is complete, run the command to make it take effect

source /etc/profile
Copy the code

Enter Go version on the console. If the version number is displayed, the installation is successful

Run the go help command to view the help

go help stocking  10109  20:09:08 Go is a toolfor 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         printGo environment information fix update packages to use new APIs fmt gofmt (reformat) package sources generate generate Go  files by processingsource
	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.
Copy the code

Congratulations, you have successfully installed GO and are ready to develop.

Note that we deliberately did not set the GOPATH command and everything behind it has been developed in modular mode, discarding the old GOPATH mode.

Don’t worry too much about modules. Slowly you will understand.

Install the Gin

Perform the installation on the command line

Go get -u github.com/gin-gonic/gin Check /usr/localIs there a gin code package in /go/pathCopy the code

Test whether Gin is installed successfully

Write a test.go file

package main

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

func main(a) {
    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
}
Copy the code

Perform the test. Go

go run test.go
Copy the code

$HOST:8080/ping {“message”:”pong”

The curl 127.0.0.1:8080 / pingCopy the code

At this point, our environment installation is almost complete 🙂

The above is just a small Demo of Gin. Feel from nothing to a oh according to the development