Skip to content

Commit

Permalink
feat: add Go example (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored May 24, 2024
1 parent 8f059aa commit 797e043
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ pip.parse(
requirements_lock = "//examples/lang_toolchains:requirements.txt",
)
use_repo(pip, "pypi")

bazel_dep(name = "rules_go", version = "0.48.0")
7 changes: 7 additions & 0 deletions examples/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_python//python:proto.bzl", "py_proto_library")
load("@rules_go//proto:def.bzl", "go_proto_library")

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

Expand All @@ -18,3 +19,9 @@ java_proto_library(
name = "foo_java_proto",
deps = [":foo_proto"],
)

go_proto_library(
name = "foo_go_proto",
importpath = "example.com/foo_proto",
proto = ":foo_proto",
)
1 change: 1 addition & 0 deletions examples/foo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

import "google/protobuf/any.proto";

option go_package = "example.com/foo_proto";
option java_package = "proto";

message Foo {
Expand Down
7 changes: 7 additions & 0 deletions examples/go/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@rules_go//go:def.bzl", "go_test")

go_test(
name = "foo_proto_test",
srcs = ["foo_proto_test.go"],
deps = ["//examples:foo_go_proto"],
)
16 changes: 16 additions & 0 deletions examples/go/foo_proto_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package proto_test

import (
"testing"

"example.com/foo_proto"
)

func TestFoo(t *testing.T) {
msg := &foo_proto.Foo{
Msg: "hello world",
}
if msg.Msg != "hello world" {
t.Fail()
}
}

0 comments on commit 797e043

Please sign in to comment.