在go语言项目中,引入本地包很常见,举个例子。
postgres_exporter 引入本地的pq。下载和运行postgres_exporter,还需要安装go语言
下载postgres数据使用驱动:git clone git@github.com:lib/pq.git
package main
import (
...
"github.com/lib/pq"
...
查看源码位置
[root@baidu1 postgres_exporter]# pwd
/gopath/postgres_exporter
[root@baidu1 pq]# pwd
/src/pq
使用 replace 将远程包替换为本地包服务
[root@baidu1 postgres_exporter]# vi go.mod
replace github.com/lib/pq => /src/pq
打包,应用
[root@segment1 postgres_exporter]# make build
>> building binaries
GO111MODULE=on /root/go/bin/promu build --prefix /home/wangdp/postgres_exporter
> postgres_exporter
go: downloading github.com/blang/semver v3.5.1+incompatible
go: downloading github.com/go-kit/kit v0.10.0
go: downloading github.com/prometheus/client_golang v1.9.0
go: downloading github.com/prometheus/common v0.17.0
go: downloading github.com/prometheus/exporter-toolkit v0.5.1
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading gopkg.in/alecthomas/kingpin.v2 v2.2.6
go: downloading github.com/go-logfmt/logfmt v0.5.0
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/cespare/xxhash/v2 v2.1.1
go: downloading github.com/golang/protobuf v1.4.3
go: downloading github.com/prometheus/procfs v0.2.0
go: downloading github.com/pkg/errors v0.9.1
go: downloading golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
go: downloading github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
go: downloading github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d
go: downloading google.golang.org/protobuf v1.23.0
go: downloading github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
go: downloading golang.org/x/net v0.0.0-20200625001655-4c5254603344
go: downloading golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e
go: downloading github.com/jpillora/backoff v1.0.0
go: downloading golang.org/x/text v0.3.2
export DATA_SOURCE_NAME=postgresql://postgres_exporter:password@localhost:5432/postgres?sslmode=disable
./postgres_exporter
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)