golang 自定义importpath
发布时间:2020-12-16 09:34:08 所属栏目:大数据 来源:网络整理
导读:golang 的包导入和其他语言有好多不一样的地方,以下是一个自定义的导入 golang 自定义导入说明 一个官方的说明 比较简单,就不翻译了,主要是说我们可以通过添加meta 数据告诉包如何进行加载 For example,import "example.org/pkg/foo"will result in the f
golang 的包导入和其他语言有好多不一样的地方,以下是一个自定义的导入 golang 自定义导入说明
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
参考实现
实现原理也是类似的 参考资料https://github.com/niemeyer/gopkg (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |