diff --git a/README.md b/README.md new file mode 100644 index 0000000..59318b6 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +## bazel 的golang示例 + +1. 更新依赖命令 +bazel run //:gazelle-update-repos +2. 编译命令 +bazel build //:hello +3. 运行命令 +bazel run //:hello + + +4. 每一个BUILD.bazel都需要配置单独的deps,内容参考deps.bzl,找不到包申明的可以上github上搜索,找到对应的bazel_deps配置作参考 diff --git a/WORKSPACE b/WORKSPACE index 32dfd89..85142f2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -20,6 +20,10 @@ http_archive( load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("//:deps.bzl", "go_dependencies") + +# gazelle:repository_macro deps.bzl%go_dependencies +go_dependencies() go_rules_dependencies() diff --git a/bazel-bazel_go_test b/bazel-bazel_go_test new file mode 120000 index 0000000..d9d024a --- /dev/null +++ b/bazel-bazel_go_test @@ -0,0 +1 @@ +/home/edison/.cache/bazel/_bazel_edison/333b9a668e98faeb0db1e492ecfd95a4/execroot/_main \ No newline at end of file diff --git a/bazel-bin b/bazel-bin index e294da3..8958e88 120000 --- a/bazel-bin +++ b/bazel-bin @@ -1 +1 @@ -/home/edison/.cache/bazel/_bazel_edison/546f64dbc186a8e485ecb66e50d42c8e/execroot/_main/bazel-out/k8-fastbuild/bin \ No newline at end of file +/home/edison/.cache/bazel/_bazel_edison/333b9a668e98faeb0db1e492ecfd95a4/execroot/_main/bazel-out/k8-fastbuild/bin \ No newline at end of file diff --git a/bazel-out b/bazel-out index 7a38bb5..e518365 120000 --- a/bazel-out +++ b/bazel-out @@ -1 +1 @@ -/home/edison/.cache/bazel/_bazel_edison/546f64dbc186a8e485ecb66e50d42c8e/execroot/_main/bazel-out \ No newline at end of file +/home/edison/.cache/bazel/_bazel_edison/333b9a668e98faeb0db1e492ecfd95a4/execroot/_main/bazel-out \ No newline at end of file diff --git a/bazel-testlogs b/bazel-testlogs index ec089dd..cd0f871 120000 --- a/bazel-testlogs +++ b/bazel-testlogs @@ -1 +1 @@ -/home/edison/.cache/bazel/_bazel_edison/546f64dbc186a8e485ecb66e50d42c8e/execroot/_main/bazel-out/k8-fastbuild/testlogs \ No newline at end of file +/home/edison/.cache/bazel/_bazel_edison/333b9a668e98faeb0db1e492ecfd95a4/execroot/_main/bazel-out/k8-fastbuild/testlogs \ No newline at end of file diff --git a/deps.bzl b/deps.bzl index 0656645..21cb9c6 100644 --- a/deps.bzl +++ b/deps.bzl @@ -2,60 +2,32 @@ load("@bazel_gazelle//:deps.bzl", "go_repository") def go_dependencies(): go_repository( - name = "com_github_cpuguy83_go_md2man_v2", - importpath = "github.com/cpuguy83/go-md2man/v2", - sum = "h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=", - version = "v2.0.2", + name = "com_github_bsm_ginkgo_v2", + importpath = "github.com/bsm/ginkgo/v2", + sum = "h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=", + version = "v2.12.0", ) go_repository( - name = "com_github_go_logr_logr", - importpath = "github.com/go-logr/logr", - sum = "h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=", - version = "v1.2.0", - ) - - go_repository( - name = "com_github_inconshreveable_mousetrap", - importpath = "github.com/inconshreveable/mousetrap", - sum = "h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=", - version = "v1.0.0", - ) - - go_repository( - name = "com_github_russross_blackfriday_v2", - importpath = "github.com/russross/blackfriday/v2", - sum = "h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=", - version = "v2.1.0", + name = "com_github_bsm_gomega", + importpath = "github.com/bsm/gomega", + sum = "h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=", + version = "v1.27.10", ) go_repository( - name = "com_github_spf13_cobra", - importpath = "github.com/spf13/cobra", - sum = "h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=", - version = "v1.5.0", + name = "com_github_cespare_xxhash_v2", + importpath = "github.com/cespare/xxhash/v2", + sum = "h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=", + version = "v2.2.0", ) go_repository( - name = "com_github_spf13_pflag", - importpath = "github.com/spf13/pflag", - sum = "h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=", - version = "v1.0.5", - ) - - go_repository( - name = "in_gopkg_check_v1", - importpath = "gopkg.in/check.v1", - sum = "h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=", - version = "v0.0.0-20161208181325-20d25e280405", - ) - - go_repository( - name = "in_gopkg_yaml_v2", - importpath = "gopkg.in/yaml.v2", - sum = "h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=", - version = "v2.4.0", + name = "com_github_dgryski_go_rendezvous", + importpath = "github.com/dgryski/go-rendezvous", + sum = "h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=", + version = "v0.0.0-20200823014737-9f7001d12a5f", ) go_repository( - name = "io_k8s_klog_v2", - importpath = "k8s.io/klog/v2", - sum = "h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=", - version = "v2.80.1", + name = "com_github_redis_go_redis_v9", + importpath = "github.com/redis/go-redis/v9", + sum = "h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=", + version = "v9.6.1", ) diff --git a/go.mod b/go.mod index 6e11867..08faca1 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,10 @@ module hello go 1.22.5 + +require github.com/redis/go-redis/v9 v9.6.1 + +require ( + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..1162e70 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4= +github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA= diff --git a/lib/BUILD.bazel b/lib/BUILD.bazel index 95de710..b0e9f61 100644 --- a/lib/BUILD.bazel +++ b/lib/BUILD.bazel @@ -7,5 +7,7 @@ go_library( ], importpath = "hello/lib", visibility = ["//visibility:public"], - + deps = [ + "@com_github_redis_go_redis_v9//:go-redis", + ], ) \ No newline at end of file diff --git a/lib/lib.go b/lib/lib.go index 510ce68..f51fd68 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -1,7 +1,18 @@ package lib -import "fmt" +import ( + "fmt" + + "github.com/redis/go-redis/v9" +) func Lib() { fmt.Println("lib") + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // 没有密码,默认值 + DB: 0, // 默认DB 0 + }) + defer rdb.Close() + }