Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the pits encountered in Gin installation

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you what are the pits encountered in Gin installation, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Initial installation of Gin

1. Install the document execution of the network officer

Go get-u github.com/gin-gonic/gin

Because it couldn't climb the wall, Baidu said it was solved with gopm. The friends in the group said that this kind of test was out of date a long time ago, and now it's all solved with go mod.

So turn on go mod.

Go env-w GOBIN=/Users/youdi/go/bingo env-w GO111MODULE=ongo env-w GOPROXY= https://goproxy.cn,direct / / using Qiniuyun's

Use go mod to manage a new project

Mkdir Gonecd Gonego mod init Gone

Check the go.mod file

Module Gonego 1.16

Once the go.mod file is created, its contents will be fully controlled by go toolchain. Go toolchain modifies and maintains go.mod files when various commands are executed, such as go get, go build, go mod, etc.

Go.mod provides four commands: module, require, replace and exclude

The module statement specifies the name (path) of the package

Dependency module specified by require statement

Replace statements can replace dependency modules

The exclude statement can ignore the dependency module

Package mainimport ("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 message 8080 (for windows "localhost:8080")}

If you execute go run main.go and run the code, you will find that go mod will automatically find dependencies on automatic download.

As a result, an error was reported

Main.go:3:8: no required module provides package github.com/gin-gonic/gin; to add it: go get github.com/gin-gonic/gin

Execute: go mod edit-require github.com/gin-gonic/gin@latest solution, specify the version of Gin

Run go run main.go again to report an error

Go: github.com/gin-gonic/gin@v1.7.4: missing go.sum entry; to add it: go mod download github.com/gin-gonic/gin

Then execute go mod tidy, execute go run main.go again, and finally run.

The above is all the contents of the article "what are the pits encountered in Gin installation?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report