自定义 Go 包的 import path 的命令行应用
source link: https://github.com/razonyang/gopkgs
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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>]
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/foo <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta name="go-import" content="example.com/foo git https://github.com/example/foo"> <meta http-equiv="refresh" content="0; url=https://pkg.go.dev/example.com/foo?tab=doc"> <title>Package example.com/foo</title> </head> <body> Nothing to see here; <a href="https://pkg.go.dev/example.com/foo?tab=doc">move along</a>. </body> </html>
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
Recommend
-
160
itchat English version itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单。 使用不到三十行的代码,你就可以完成一...
-
92
go get时遇到超时错误 go: golang.org/x/[email protected]: unrecognized import path "golang.org/x/sync" (https fetch: Get https://golang.org/x/sync?go-get=1: dial tcp 216.239.37.1:443: i/o t...
-
46
tags: java, troubleshooting, monitor,jvm 一句话概括:原来jdk自带的命令行工具如此好用,本文将详细介绍。 1 引言 监测java应用,最方便的就是直接使用jdk提供的现成工具,在jdk的安装的bin目录下,已经...
-
29
原文链接: https://idoubi.cc/posts/create-a-cli-tool-in-macos/ 使用 MacOS 做开发的朋友都知道,我们一般会使用 Homebrew 做软件包管理,经常会用到...
-
7
Introduction The import statement is usually the first thing you see at the top of any Python file. We use it all the time, yet it is still a bit mysterious to many people. This tutorial will walk through how import wor...
-
6
正常情况下我们安装一个 npm 包只需要执行 npm install 或者 yarn 就可以了,这基本上都是在发布环境。当我们自定义的 npm 包需要在测试阶段根据环境动态设置一些参数时就显得有些麻烦了。如果能在 npm install 时传递一些参数来提供内部 npm 包读取就会变的比...
-
3
Jenkins脚本命令行应用总结 Jenkins 2.304 脚本命令行入口 Jenkins主页→系统管理→脚本命令行 例子:获取所有自由风格项目及相关项目信息 def projects = Jenkins.instance.projects.collect { it } //...
-
1
来自jetbrains Go 语言现状调查报告 显示:在go开发者中使用go开发实用小程序的比例为31%仅次于web,go得益于跨平台、无依赖的特性,用来编写命令行或系统管理这类小程序非常...
-
2
在所有终端中使用相同界面,Starship 帮助你自定义命令行 在所有终端中使用相同界面,Starship 帮助你自定义命令行 04 月 29 日 Matrix 首页推荐
-
2
一个构建Python命令行应用的开源库 - 迷途小书童的Note迷途小书童的Note 迷途小书童的Note >
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK