自定义 Go 包的 import path 的命令行应用
2015 年 10 月 31 日
GOPKGs
gopkgs
is a CLI application and HTTP service that manage custom import path of your Go packages.
The major advantages of using custom import path is that you don’t need to change the import path when you are going to host your code elsewhere.
Online preview
$ curl "https://clevergo.tech/clevergo?go-get=1" $ curl "https://clevergo.tech/captchas?go-get=1" $ curl "https://clevergo.tech/form?go-get=1"
Installation
Source
$ git clone https://github.com/razonyang/gopkgs.git $ cd gopkgs $ packr2 build --tag [database]
-
database
:mysql
,sqlite3
orpostgres
.
go get -u github.com/gobuffalo/packr/v2/packr2
for installing packr2
.
Binary
Checkout releases page and download.
Configuration
Configuration is a JSON file.
{ "addr": ":8080", "db": { "driver": "sqlite3", "dsn": "gopkgs.db", "tableName": "packages" } }
-
addr
: HTTP server address. -
db
:-
dsn
: data source name, depends on what driver you use.-
sqlite3
:/path/to/gopkgs.db
-
mysql
:user:password@tcp(localhost:3306)/gopkgs?charset=utf8mb4&parseTime=True&loc=Local
-
postgres
:postgres://user:password@localhost/gopkgs?sslmode=verify-full
-
-
tableName
: the name of packages table.
-
The config.json
of the current directory will be used by default, you can specify the configuration file via -c
or --config
flag:
$ gopkgs -c /etc/gopkgs/config.json
Usage
Start HTTP server
$ gopkgs serve
You can use supervisord to manage gopkgs HTTP service.
You may also need to set up a reverse proxy, let’s take Nginx as example:
location / { try_files $uri $uri/ @gopkgsproxy; } location @gopkgsproxy { proxy_set_header Host $host; proxy_pass http://127.0.0.1:8080; }
Add package
$ gopkgs add []
prefix vcs repo-root docs-url
$ gopkgs add \ example.com/foo \ git \ https://github.com/example/foo
And then checkout the output.
$ curl https://example.com/fooPackage example.com/foo Nothing to see here; move along.
Show package
$ gopkgs show example.com/foo example.com/foo vcs : git root: https://github.com/example/foo docs: https://pkg.go.dev/example.com/foo?tab=doc
Edit package
Modify VCS
$ gopkgs set-vcs example.com/foo svn
Repository Root
$ gopkgs set-root example.com/foo https://gitlab.com/example/foo
Documentations
$ gopkgs set-docs example.com/foo https://docs.example.com/foo
Verify that everything is OK
$ gopkgs show example.com/foo example.com/foo vcs : svn root: https://gitlab.com/example/foo docs: https://docs.example.com/foo
Remove pacakge
$ gopkgs remove example.com/foo
Help
$ gopkgs help