-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
806c1be
commit 88d3201
Showing
5 changed files
with
136 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,70 @@ | ||
|
||
## 初始化工程 | ||
|
||
```bash | ||
go list -m all | ||
go install | ||
go clean -modcache | ||
``` | ||
mkdir mod2 | ||
cd mod2 | ||
go mod init mod2 | ||
``` | ||
|
||
## 安装包 | ||
|
||
```bash | ||
go get -m github.com/gin-gonic/[email protected] | ||
|
||
go get github.com/gorilla/mux # 匹配最新的一个 tag | ||
go get github.com/gorilla/mux@latest # 和上面一样 | ||
go get github.com/gorilla/[email protected] # 匹配 v1.6.2 | ||
go get github.com/gorilla/mux@e3702bed2 # 匹配 v1.6.2 | ||
go get github.com/gorilla/mux@c856192 # 匹配 c85619274f5d | ||
go get github.com/gorilla/mux@master # 匹配 master 分支 | ||
``` | ||
|
||
1. 通过 `go get` 切换版本 | ||
2. 执行 `go mod vendor` 将依赖复制到vendor下 | ||
3. 通过 `go mod tidy` 命令可以移除 `go.mod` 中不再使用的依赖 | ||
|
||
## 设置代理 | ||
|
||
```bash | ||
# bash mac | ||
export GOPROXY=https://goproxy.io | ||
``` | ||
|
||
## mod 命令 | ||
|
||
```bash | ||
go help mod | ||
# Go mod provides access to operations on modules. | ||
|
||
# Note that support for modules is built into all the go commands, | ||
# not just 'go mod'. For example, day-to-day adding, removing, upgrading, | ||
# and downgrading of dependencies should be done using 'go get'. | ||
# See 'go help modules' for an overview of module functionality. | ||
|
||
Usage: | ||
|
||
go mod <command> [arguments] | ||
|
||
The commands are: | ||
|
||
download download modules to local cache | ||
edit edit go.mod from tools or scripts | ||
graph print module requirement graph | ||
init initialize new module in current directory | ||
tidy add missing and remove unused modules | ||
vendor make vendored copy of dependencies | ||
verify verify dependencies have expected content | ||
why explain why packages or modules are needed | ||
|
||
Use "go help mod <command>" for more information about a command. | ||
``` | ||
|
||
- `download`: download modules to local cache (下载依赖的module到本地cache) | ||
- `edit`: edit go.mod from tools or scripts (编辑go.mod文件) | ||
- `graph`: print module requirement graph (打印模块依赖图) | ||
- `init`: initialize new module in current directory (再当前文件夹下初始化一个新的module, 创建go.mod文件) | ||
- `tidy`: add missing and remove unused modules (增加丢失的module,去掉未用的module) | ||
- `vendor`: make vendored copy of dependencies (将依赖复制到vendor下) | ||
- `verify`: verify dependencies have expected content (校验依赖) | ||
- `why`: explain why packages or modules are needed (解释为什么需要依赖) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
module "https://github.com/gin-gonic/gin.git" | ||
module mod2 | ||
|
||
require ( | ||
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect | ||
github.com/gin-gonic/gin v1.3.0 | ||
github.com/golang/protobuf v1.2.0 // indirect | ||
github.com/json-iterator/go v1.1.5 // indirect | ||
github.com/mattn/go-isatty v0.0.4 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.1 // indirect | ||
github.com/stretchr/testify v1.3.0 // indirect | ||
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 // indirect | ||
golang.org/x/net v0.0.0-20190110200230-915654e7eabc // indirect | ||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 // indirect | ||
golang.org/x/sys v0.0.0-20190116161447-11f53e031339 // indirect | ||
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect | ||
gopkg.in/go-playground/validator.v8 v8.18.2 // indirect | ||
gopkg.in/yaml.v2 v2.2.2 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
|
||
import ( | ||
"html/template" | ||
"log" | ||
"os" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
var html = template.Must(template.New("https").Parse(` | ||
<html> | ||
<head> | ||
<title>Https Test</title> | ||
</head> | ||
<body> | ||
<h1 style="color:red;">Welcome, golang!</h1> | ||
</body> | ||
</html> | ||
`)) | ||
|
||
|
||
func main() { | ||
logger := log.New(os.Stderr, "", 0) | ||
logger.Println("[WARNING] DON'T USE THE EMBED CERTS FROM THIS EXAMPLE IN PRODUCTION ENVIRONMENT, GENERATE YOUR OWN!") | ||
|
||
r := gin.Default() | ||
r.SetHTMLTemplate(html) | ||
|
||
r.GET("/", func(c *gin.Context) { | ||
c.HTML(200, "https", gin.H{ | ||
"status": "success", | ||
}) | ||
}) | ||
|
||
// Listen and Server in https://127.0.0.1:8080 | ||
r.Run(":8083") | ||
} |
This file was deleted.
Oops, something went wrong.