Skip to content

Commit 797e043

Browse files
authored
feat: add Go example (#10)
1 parent 8f059aa commit 797e043

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

MODULE.bazel

+2
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ pip.parse(
5050
requirements_lock = "//examples/lang_toolchains:requirements.txt",
5151
)
5252
use_repo(pip, "pypi")
53+
54+
bazel_dep(name = "rules_go", version = "0.48.0")

examples/BUILD

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@rules_proto//proto:defs.bzl", "proto_library")
22
load("@rules_python//python:proto.bzl", "py_proto_library")
3+
load("@rules_go//proto:def.bzl", "go_proto_library")
34

45
package(default_visibility = ["//visibility:public"])
56

@@ -18,3 +19,9 @@ java_proto_library(
1819
name = "foo_java_proto",
1920
deps = [":foo_proto"],
2021
)
22+
23+
go_proto_library(
24+
name = "foo_go_proto",
25+
importpath = "example.com/foo_proto",
26+
proto = ":foo_proto",
27+
)

examples/foo.proto

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ syntax = "proto3";
22

33
import "google/protobuf/any.proto";
44

5+
option go_package = "example.com/foo_proto";
56
option java_package = "proto";
67

78
message Foo {

examples/go/BUILD

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_go//go:def.bzl", "go_test")
2+
3+
go_test(
4+
name = "foo_proto_test",
5+
srcs = ["foo_proto_test.go"],
6+
deps = ["//examples:foo_go_proto"],
7+
)

examples/go/foo_proto_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package proto_test
2+
3+
import (
4+
"testing"
5+
6+
"example.com/foo_proto"
7+
)
8+
9+
func TestFoo(t *testing.T) {
10+
msg := &foo_proto.Foo{
11+
Msg: "hello world",
12+
}
13+
if msg.Msg != "hello world" {
14+
t.Fail()
15+
}
16+
}

0 commit comments

Comments
 (0)