Skip to content

Commit 1f9902e

Browse files
committed
Cleanup of grpc go generation code
I'd previously generated this in two places, and looking at it through Godoc, it seemed like a code smell. Having the generated code in a single place seems like the cleaner option.
1 parent a5f2b97 commit 1f9902e

5 files changed

Lines changed: 20 additions & 273 deletions

File tree

build/build-image/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# ForceUpdate 1 -- change here if you need to force a rebuild
15+
# ForceUpdate 2 -- change here if you need to force a rebuild
1616

1717
# compiling proto + grpc takes an exceptionally long time
1818
# so we'll use that as the base.

build/build-image/gen-grpc-go.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
# limitations under the License.
1616

1717
cd /go/src/agones.dev/agones
18-
protoc -I . sdk.proto --go_out=plugins=grpc:sdks/go
19-
cat ./build/boilerplate.go.txt ./sdks/go/sdk.pb.go >> ./sdk.pb.go
18+
protoc -I . sdk.proto --go_out=plugins=grpc:pkg/sdk
19+
cat ./build/boilerplate.go.txt ./pkg/sdk/sdk.pb.go >> ./sdk.pb.go
2020
goimports -w ./sdk.pb.go
21-
cp ./sdk.pb.go ./pkg/sdk
22-
mv ./sdk.pb.go ./sdks/go
21+
mv ./sdk.pb.go ./pkg/sdk

sdks/go/sdk.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Package sdk is the Go game server sdk
1516
package sdk
1617

1718
import (
1819
"fmt"
19-
2020
"time"
2121

22+
"agones.dev/agones/pkg/sdk"
2223
"github.com/pkg/errors"
2324
"golang.org/x/net/context"
2425
"google.golang.org/grpc"
@@ -28,9 +29,9 @@ const port = 59357
2829

2930
// SDK is an instance of the Agones SDK
3031
type SDK struct {
31-
client SDKClient
32+
client sdk.SDKClient
3233
ctx context.Context
33-
health SDK_HealthClient
34+
health sdk.SDK_HealthClient
3435
}
3536

3637
// NewSDK starts a new SDK instance, and connects to
@@ -46,27 +47,27 @@ func NewSDK() (*SDK, error) {
4647
if err != nil {
4748
return s, errors.Wrapf(err, "could not connect to %s", addr)
4849
}
49-
s.client = NewSDKClient(conn)
50+
s.client = sdk.NewSDKClient(conn)
5051
s.health, err = s.client.Health(s.ctx)
5152
return s, errors.Wrap(err, "could not set up health check")
5253
}
5354

5455
// Ready marks the Game Server as ready to
5556
// receive connections
5657
func (s *SDK) Ready() error {
57-
_, err := s.client.Ready(s.ctx, &Empty{})
58+
_, err := s.client.Ready(s.ctx, &sdk.Empty{})
5859
return errors.Wrap(err, "could not send Ready message")
5960
}
6061

6162
// Shutdown marks the Game Server as ready to
6263
// shutdown
6364
func (s *SDK) Shutdown() error {
64-
_, err := s.client.Shutdown(s.ctx, &Empty{})
65+
_, err := s.client.Shutdown(s.ctx, &sdk.Empty{})
6566
return errors.Wrapf(err, "could not send Shutdown message")
6667
}
6768

6869
// Health sends a ping to the health
6970
// check to indicate that this server is healthy
7071
func (s *SDK) Health() error {
71-
return errors.Wrap(s.health.Send(&Empty{}), "could not send Health ping")
72+
return errors.Wrap(s.health.Send(&sdk.Empty{}), "could not send Health ping")
7273
}

sdks/go/sdk.pb.go

Lines changed: 0 additions & 254 deletions
This file was deleted.

sdks/go/sdk_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package sdk
1717
import (
1818
"testing"
1919

20+
"agones.dev/agones/pkg/sdk"
2021
"github.com/stretchr/testify/assert"
2122
"golang.org/x/net/context"
2223
"google.golang.org/grpc"
@@ -50,39 +51,39 @@ func TestSDK(t *testing.T) {
5051
assert.True(t, sm.shutdown)
5152
}
5253

53-
var _ SDKClient = &sdkMock{}
54-
var _ SDK_HealthClient = &healthMock{}
54+
var _ sdk.SDKClient = &sdkMock{}
55+
var _ sdk.SDK_HealthClient = &healthMock{}
5556

5657
type sdkMock struct {
5758
ready bool
5859
shutdown bool
5960
hm *healthMock
6061
}
6162

62-
func (m *sdkMock) Ready(ctx context.Context, e *Empty, opts ...grpc.CallOption) (*Empty, error) {
63+
func (m *sdkMock) Ready(ctx context.Context, e *sdk.Empty, opts ...grpc.CallOption) (*sdk.Empty, error) {
6364
m.ready = true
6465
return e, nil
6566
}
6667

67-
func (m *sdkMock) Shutdown(ctx context.Context, e *Empty, opts ...grpc.CallOption) (*Empty, error) {
68+
func (m *sdkMock) Shutdown(ctx context.Context, e *sdk.Empty, opts ...grpc.CallOption) (*sdk.Empty, error) {
6869
m.shutdown = true
6970
return e, nil
7071
}
7172

72-
func (m *sdkMock) Health(ctx context.Context, opts ...grpc.CallOption) (SDK_HealthClient, error) {
73+
func (m *sdkMock) Health(ctx context.Context, opts ...grpc.CallOption) (sdk.SDK_HealthClient, error) {
7374
return m.hm, nil
7475
}
7576

7677
type healthMock struct {
7778
healthy bool
7879
}
7980

80-
func (h *healthMock) Send(*Empty) error {
81+
func (h *healthMock) Send(*sdk.Empty) error {
8182
h.healthy = true
8283
return nil
8384
}
8485

85-
func (h *healthMock) CloseAndRecv() (*Empty, error) {
86+
func (h *healthMock) CloseAndRecv() (*sdk.Empty, error) {
8687
panic("implement me")
8788
}
8889

0 commit comments

Comments
 (0)