标签:win foo 修改 自定义 server art 127.0.0.1 port 导入
golang 的包导入和其他语言有好多不一样的地方,以下是一个自定义的导入
比较简单,就不翻译了,主要是说我们可以通过添加meta 数据告诉包如何进行加载
For example,
import "example.org/pkg/foo"
will result in the following requests:
https://example.org/pkg/foo?go-get=1 (preferred)
http://example.org/pkg/foo?go-get=1 (fallback, only with -insecure)
If that page contains the meta tag
<meta name="go-import" content="example.org git https://code.org/r/p/exproj">
the go tool will verify that https://example.org/?go-get=1 contains the
same meta tag and then git clone https://code.org/r/p/exproj into
GOPATH/src/example.org.
package main
import (
"log"
// 自定义的地址,实际是从github 导入包
"rongdemo.com"
)
func main() {
log.Println(shortid.Generate())
}
/etc/hosts
127.0.0.1 rongdemo.com
yarn inti -y
yarn add live-server --dev
修改package.json
{
"name": "golang-web-package",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"live-server": "^1.2.0"
},
"scripts": {
"start": "live-server"
}
}
nano index.html
<html>
<meta name="go-import" content="rongdemo.com git https://github.com/teris-io/shortid" />
<body>
golang package
</body>
</html>
yarn start
dep init
gopkg.in
实现原理也是类似的
https://github.com/niemeyer/gopkg
https://golang.org/cmd/go/#hdr-Remote_import_paths
https://github.com/rongfengliang/golang-customimport
标签:win foo 修改 自定义 server art 127.0.0.1 port 导入
原文地址:https://www.cnblogs.com/rongfengliang/p/9529994.html