自定义 Go 包的 import path 的命令行应用

栏目: IT技术 · 发布时间: 4年前

内容简介: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.

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 or postgres .

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C++沉思录

C++沉思录

Andrew Koenig、Barbara Moo / 黄晓春、孟岩(审校) / 人民邮电出版社 / 2008-1 / 55.00元

《C++沉思录》基于作者在知名技术杂志发表的技术文章、世界各地发表的演讲以及斯坦福大学的课程讲义整理、写作而成,融聚了作者10多年C++程序生涯的真知灼见。全书分为6篇32章,分别对C++语言的历史和特点、类和继承、STL与泛型编程、库的设计等几大技术话题进行了详细而深入的讨论,细微之处几乎涵盖了C++所有的设计思想和技术细节。全书通过精心挑选的实例,向读者传达先进的程序设计的方法和理念。一起来看看 《C++沉思录》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具