Ver código fonte

first commit from code from git.skogstorpet.nu/staffan/service

Staffan Olsson 3 anos atrás
commit
a9aaf759fe
15 arquivos alterados com 810 adições e 0 exclusões
  1. 6 0
      .gitignore
  2. 8 0
      LICENSE
  3. 44 0
      README.md
  4. 61 0
      client.go
  5. 336 0
      env.pb.go
  6. 17 0
      env.proto
  7. 42 0
      environ.go
  8. 23 0
      example/client/main.go
  9. 41 0
      example/run_linux.sh
  10. 22 0
      example/server/main.go
  11. 11 0
      go.mod
  12. 123 0
      go.sum
  13. 22 0
      scripts/gen_grpc.sh
  14. 21 0
      scripts/install_protoc.sh
  15. 33 0
      server.go

+ 6 - 0
.gitignore

@@ -0,0 +1,6 @@
+# SPDX-FileCopyrightText: 2021 Staffan Olsson <naffatso@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+
+.tools/
+.examples/

+ 8 - 0
LICENSE

@@ -0,0 +1,8 @@
+MIT License
+Copyright (c) 2021 Staffan Olsson <naffatso@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 44 - 0
README.md

@@ -0,0 +1,44 @@
+# environ
+
+A simple lib to retrieve build time environment for client and server.
+
+## Usage
+
+```bash
+go get -u git.skogstorpet.nu/staffan/environ
+```
+
+The server should implement the [EnvironmentSvc](env.proto) service. Given a
+grpc connection to the server, the client should be able to fetch the
+environment from the server.
+
+To build an enviorn aware executable, build using these build settings:
+
+```bash
+
+# Version of program could be set by a git tag.
+export VERSION=$(git describe --tags)
+export GIT_COMMIT=$(git rev-list -1 HEAD --abbrev-commit)
+export BUILD_TIME="$(date +%FT%T)"
+export GO_OS_ARCH="$(go env GOOS)/$(go env GOARCH)"
+export API_VERSION=$(cat $PROJ_ROOT/api.version)
+
+echo "Version: $VERSION"
+echo "GIT_COMMIT: $GIT_COMMIT"
+echo "BUILD_TIME: $BUILD_TIME"
+echo "GO_OS_ARCH: $GO_OS_ARCH"
+echo "API_VERSION: $API_VERSION"
+
+export LD_FLAGS="-X git.skogstorpet.nu/staffan/environ.GitCommit=$GIT_COMMIT \
+    -X git.skogstorpet.nu/staffan/environ.BuildTime=$BUILD_TIME \
+    -X git.skogstorpet.nu/staffan/environ.GoOsArch=$GO_OS_ARCH \
+    -X git.skogstorpet.nu/staffan/environ.Version=$VERSION \
+    -X git.skogstorpet.nu/staffan/environ.APIVersion=$API_VERSION"
+
+# Build CLI
+go build -ldflags "$LD_FLAGS" /your/path/to/client_main.go
+
+# Build server
+go build -ldflags "$LD_FLAGS" /your/path/to/server_main.go
+
+```

+ 61 - 0
client.go

@@ -0,0 +1,61 @@
+package environ
+
+import (
+	context "context"
+	"fmt"
+	"io"
+	"runtime"
+	"text/tabwriter"
+	"time"
+
+	"google.golang.org/grpc"
+)
+
+// GetBuildInfo uses an existing grpc connection to request the server eviron and returns that with the client environ.
+func GetBuildInfo(conn *grpc.ClientConn, timeout time.Duration) (clientEnv *Environment, serverEnv *Environment, err error) {
+	clientEnv = &Environment{
+		Version:    Version,
+		GitCommit:  GitCommit,
+		BuildTime:  BuildTime,
+		GoOsArch:   GoOsArch,
+		ApiVersion: APIVersion,
+		GoVersion:  runtime.Version(),
+	}
+
+	svcClient := NewEnvironmentSvcClient(conn)
+
+	ctx, cancel := context.WithTimeout(context.Background(), timeout)
+	defer cancel()
+	rsp, err := svcClient.GetEnvironment(ctx, &Void{})
+	if err != nil {
+		return clientEnv, nil, fmt.Errorf("failed to contact environ server")
+	}
+	return clientEnv, rsp, nil
+
+}
+
+// PrintBuildInfo prints the environment for client and server, if they are defined
+func PrintBuildInfo(out io.Writer, clientEnv, serverEnv *Environment) {
+	if clientEnv != nil {
+		w := tabwriter.NewWriter(out, 0, 0, 1, ' ', 0)
+		fmt.Fprintf(w, "Client:")
+		fmt.Fprintf(w, " Version:\t%s\n", clientEnv.Version)
+		fmt.Fprintf(w, " API version:\t%s\n", clientEnv.ApiVersion)
+		fmt.Fprintf(w, " Go version:\t%s\n", clientEnv.Version)
+		fmt.Fprintf(w, " Git commit:\t%s\n", clientEnv.GitCommit)
+		fmt.Fprintf(w, " Built:\t%s\n", clientEnv.BuildTime)
+		fmt.Fprintf(w, " OS/Arch:\t%s\n", clientEnv.GoOsArch)
+		w.Flush()
+	}
+	if serverEnv != nil {
+		w := tabwriter.NewWriter(out, 0, 0, 1, ' ', 0)
+		fmt.Fprintln(w, "Server")
+		fmt.Fprintf(w, " Version:\t%s\n", serverEnv.Version)
+		fmt.Fprintf(w, " API version:\t%s\n", serverEnv.ApiVersion)
+		fmt.Fprintf(w, " Go version:\t%s\n", serverEnv.GoVersion)
+		fmt.Fprintf(w, " Git commit:\t%s\n", serverEnv.GitCommit)
+		fmt.Fprintf(w, " Built:\t%s\n", serverEnv.BuildTime)
+		fmt.Fprintf(w, " OS/Arch:\t%s\n", serverEnv.GoOsArch)
+		w.Flush()
+	}
+}

+ 336 - 0
env.pb.go

@@ -0,0 +1,336 @@
+// Code generated by protoc-gen-go. DO NOT EDIT.
+// versions:
+// 	protoc-gen-go v1.26.0
+// 	protoc        v3.14.0
+// source: env.proto
+
+package environ
+
+import (
+	context "context"
+	grpc "google.golang.org/grpc"
+	codes "google.golang.org/grpc/codes"
+	status "google.golang.org/grpc/status"
+	protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+	protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+	reflect "reflect"
+	sync "sync"
+)
+
+const (
+	// Verify that this generated code is sufficiently up-to-date.
+	_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
+	// Verify that runtime/protoimpl is sufficiently up-to-date.
+	_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
+)
+
+type Void struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+}
+
+func (x *Void) Reset() {
+	*x = Void{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_env_proto_msgTypes[0]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *Void) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*Void) ProtoMessage() {}
+
+func (x *Void) ProtoReflect() protoreflect.Message {
+	mi := &file_env_proto_msgTypes[0]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use Void.ProtoReflect.Descriptor instead.
+func (*Void) Descriptor() ([]byte, []int) {
+	return file_env_proto_rawDescGZIP(), []int{0}
+}
+
+type Environment struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Version    string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
+	GitCommit  string `protobuf:"bytes,2,opt,name=git_commit,json=gitCommit,proto3" json:"git_commit,omitempty"`
+	BuildTime  string `protobuf:"bytes,3,opt,name=build_time,json=buildTime,proto3" json:"build_time,omitempty"`
+	GoOsArch   string `protobuf:"bytes,4,opt,name=go_os_arch,json=goOsArch,proto3" json:"go_os_arch,omitempty"`
+	ApiVersion string `protobuf:"bytes,5,opt,name=api_version,json=apiVersion,proto3" json:"api_version,omitempty"`
+	GoVersion  string `protobuf:"bytes,6,opt,name=go_version,json=goVersion,proto3" json:"go_version,omitempty"`
+}
+
+func (x *Environment) Reset() {
+	*x = Environment{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_env_proto_msgTypes[1]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *Environment) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*Environment) ProtoMessage() {}
+
+func (x *Environment) ProtoReflect() protoreflect.Message {
+	mi := &file_env_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use Environment.ProtoReflect.Descriptor instead.
+func (*Environment) Descriptor() ([]byte, []int) {
+	return file_env_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *Environment) GetVersion() string {
+	if x != nil {
+		return x.Version
+	}
+	return ""
+}
+
+func (x *Environment) GetGitCommit() string {
+	if x != nil {
+		return x.GitCommit
+	}
+	return ""
+}
+
+func (x *Environment) GetBuildTime() string {
+	if x != nil {
+		return x.BuildTime
+	}
+	return ""
+}
+
+func (x *Environment) GetGoOsArch() string {
+	if x != nil {
+		return x.GoOsArch
+	}
+	return ""
+}
+
+func (x *Environment) GetApiVersion() string {
+	if x != nil {
+		return x.ApiVersion
+	}
+	return ""
+}
+
+func (x *Environment) GetGoVersion() string {
+	if x != nil {
+		return x.GoVersion
+	}
+	return ""
+}
+
+var File_env_proto protoreflect.FileDescriptor
+
+var file_env_proto_rawDesc = []byte{
+	0x0a, 0x09, 0x65, 0x6e, 0x76, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x65, 0x6e, 0x76,
+	0x69, 0x72, 0x6f, 0x6e, 0x22, 0x06, 0x0a, 0x04, 0x56, 0x6f, 0x69, 0x64, 0x22, 0xc3, 0x01, 0x0a,
+	0x0b, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07,
+	0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76,
+	0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x67, 0x69, 0x74, 0x5f, 0x63, 0x6f,
+	0x6d, 0x6d, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x67, 0x69, 0x74, 0x43,
+	0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x5f, 0x74,
+	0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x62, 0x75, 0x69, 0x6c, 0x64,
+	0x54, 0x69, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x0a, 0x67, 0x6f, 0x5f, 0x6f, 0x73, 0x5f, 0x61, 0x72,
+	0x63, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x6f, 0x4f, 0x73, 0x41, 0x72,
+	0x63, 0x68, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x70, 0x69, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
+	0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x70, 0x69, 0x56, 0x65, 0x72, 0x73,
+	0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x67, 0x6f, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
+	0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x67, 0x6f, 0x56, 0x65, 0x72, 0x73, 0x69,
+	0x6f, 0x6e, 0x32, 0x47, 0x0a, 0x0e, 0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e,
+	0x74, 0x53, 0x76, 0x63, 0x12, 0x35, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x45, 0x6e, 0x76, 0x69, 0x72,
+	0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x0d, 0x2e, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e,
+	0x2e, 0x56, 0x6f, 0x69, 0x64, 0x1a, 0x14, 0x2e, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x2e,
+	0x45, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x42, 0x30, 0x5a, 0x2e, 0x67,
+	0x69, 0x74, 0x2e, 0x73, 0x6b, 0x6f, 0x67, 0x73, 0x74, 0x6f, 0x72, 0x70, 0x65, 0x74, 0x2e, 0x6e,
+	0x75, 0x2f, 0x73, 0x74, 0x61, 0x66, 0x66, 0x61, 0x6e, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
+	0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x65, 0x6e, 0x76, 0x69, 0x72, 0x6f, 0x6e, 0x62, 0x06, 0x70,
+	0x72, 0x6f, 0x74, 0x6f, 0x33,
+}
+
+var (
+	file_env_proto_rawDescOnce sync.Once
+	file_env_proto_rawDescData = file_env_proto_rawDesc
+)
+
+func file_env_proto_rawDescGZIP() []byte {
+	file_env_proto_rawDescOnce.Do(func() {
+		file_env_proto_rawDescData = protoimpl.X.CompressGZIP(file_env_proto_rawDescData)
+	})
+	return file_env_proto_rawDescData
+}
+
+var file_env_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_env_proto_goTypes = []interface{}{
+	(*Void)(nil),        // 0: environ.Void
+	(*Environment)(nil), // 1: environ.Environment
+}
+var file_env_proto_depIdxs = []int32{
+	0, // 0: environ.EnvironmentSvc.GetEnvironment:input_type -> environ.Void
+	1, // 1: environ.EnvironmentSvc.GetEnvironment:output_type -> environ.Environment
+	1, // [1:2] is the sub-list for method output_type
+	0, // [0:1] is the sub-list for method input_type
+	0, // [0:0] is the sub-list for extension type_name
+	0, // [0:0] is the sub-list for extension extendee
+	0, // [0:0] is the sub-list for field type_name
+}
+
+func init() { file_env_proto_init() }
+func file_env_proto_init() {
+	if File_env_proto != nil {
+		return
+	}
+	if !protoimpl.UnsafeEnabled {
+		file_env_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*Void); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_env_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*Environment); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+	}
+	type x struct{}
+	out := protoimpl.TypeBuilder{
+		File: protoimpl.DescBuilder{
+			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
+			RawDescriptor: file_env_proto_rawDesc,
+			NumEnums:      0,
+			NumMessages:   2,
+			NumExtensions: 0,
+			NumServices:   1,
+		},
+		GoTypes:           file_env_proto_goTypes,
+		DependencyIndexes: file_env_proto_depIdxs,
+		MessageInfos:      file_env_proto_msgTypes,
+	}.Build()
+	File_env_proto = out.File
+	file_env_proto_rawDesc = nil
+	file_env_proto_goTypes = nil
+	file_env_proto_depIdxs = nil
+}
+
+// Reference imports to suppress errors if they are not otherwise used.
+var _ context.Context
+var _ grpc.ClientConnInterface
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the grpc package it is being compiled against.
+const _ = grpc.SupportPackageIsVersion6
+
+// EnvironmentSvcClient is the client API for EnvironmentSvc service.
+//
+// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
+type EnvironmentSvcClient interface {
+	GetEnvironment(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Environment, error)
+}
+
+type environmentSvcClient struct {
+	cc grpc.ClientConnInterface
+}
+
+func NewEnvironmentSvcClient(cc grpc.ClientConnInterface) EnvironmentSvcClient {
+	return &environmentSvcClient{cc}
+}
+
+func (c *environmentSvcClient) GetEnvironment(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Environment, error) {
+	out := new(Environment)
+	err := c.cc.Invoke(ctx, "/environ.EnvironmentSvc/GetEnvironment", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+// EnvironmentSvcServer is the server API for EnvironmentSvc service.
+type EnvironmentSvcServer interface {
+	GetEnvironment(context.Context, *Void) (*Environment, error)
+}
+
+// UnimplementedEnvironmentSvcServer can be embedded to have forward compatible implementations.
+type UnimplementedEnvironmentSvcServer struct {
+}
+
+func (*UnimplementedEnvironmentSvcServer) GetEnvironment(context.Context, *Void) (*Environment, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method GetEnvironment not implemented")
+}
+
+func RegisterEnvironmentSvcServer(s *grpc.Server, srv EnvironmentSvcServer) {
+	s.RegisterService(&_EnvironmentSvc_serviceDesc, srv)
+}
+
+func _EnvironmentSvc_GetEnvironment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(Void)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(EnvironmentSvcServer).GetEnvironment(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/environ.EnvironmentSvc/GetEnvironment",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(EnvironmentSvcServer).GetEnvironment(ctx, req.(*Void))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+var _EnvironmentSvc_serviceDesc = grpc.ServiceDesc{
+	ServiceName: "environ.EnvironmentSvc",
+	HandlerType: (*EnvironmentSvcServer)(nil),
+	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "GetEnvironment",
+			Handler:    _EnvironmentSvc_GetEnvironment_Handler,
+		},
+	},
+	Streams:  []grpc.StreamDesc{},
+	Metadata: "env.proto",
+}

+ 17 - 0
env.proto

@@ -0,0 +1,17 @@
+syntax = "proto3";
+option go_package = "git.skogstorpet.nu/staffan/service/pkg/environ";
+package environ;
+
+message Void {};
+service EnvironmentSvc {
+  rpc GetEnvironment(Void) returns (Environment);
+}
+
+message Environment {
+  string version = 1;
+  string git_commit = 2;
+  string build_time = 3;
+  string go_os_arch = 4;
+  string api_version = 5;
+  string go_version = 6;
+}

+ 42 - 0
environ.go

@@ -0,0 +1,42 @@
+// SPDX-FileCopyrightText: 2021 Staffan Olsson <naffatso@gmail.com>
+//
+// SPDX-License-Identifier: MIT
+
+package environ
+
+var (
+	// The following variables are set at build time by scripts/build.sh
+
+	// GitCommit is the commit of the build
+	GitCommit string
+
+	// BuildTime is the time the exe was built
+	BuildTime string
+
+	// GoOsArch is the OS/architecture for which the exe was built
+	GoOsArch string
+
+	// Version is the git tag of the source
+	Version string
+
+	// APIVersion is from api/version.txt
+	APIVersion string
+)
+
+func init() {
+	if GitCommit == "" {
+		GitCommit = "<debug>"
+	}
+	if BuildTime == "" {
+		BuildTime = "<debug>"
+	}
+	if GoOsArch == "" {
+		GoOsArch = "<debug>"
+	}
+	if Version == "" {
+		Version = "<debug>"
+	}
+	if APIVersion == "" {
+		APIVersion = "<debug>"
+	}
+}

+ 23 - 0
example/client/main.go

@@ -0,0 +1,23 @@
+package main
+
+import (
+	"fmt"
+	"os"
+	"time"
+
+	"git.skogstorpet.nu/staffan/environ"
+	"google.golang.org/grpc"
+)
+
+func main() {
+	clientConn, err := grpc.Dial("127.0.0.1:12345", grpc.WithInsecure())
+	if err != nil {
+		panic(err)
+	}
+	defer clientConn.Close()
+	clientEnv, serverEnv, err := environ.GetBuildInfo(clientConn, time.Second)
+	if err != nil {
+		fmt.Printf("error: %v\n", err)
+	}
+	environ.PrintBuildInfo(os.Stdout, clientEnv, serverEnv)
+}

+ 41 - 0
example/run_linux.sh

@@ -0,0 +1,41 @@
+#!/bin/bash
+
+PROJ_ROOT=$(realpath "$(
+    cd "$(dirname "$0")" >/dev/null 2>&1
+    pwd -P
+)"/..)
+
+# Version of program could be set by a git tag.
+export VERSION=$(git describe --tags)
+export GIT_COMMIT=$(git rev-list -1 HEAD --abbrev-commit)
+export BUILD_TIME="$(date +%FT%T)"
+export GO_OS_ARCH="$(go env GOOS)/$(go env GOARCH)"
+export API_VERSION=$(cat $PROJ_ROOT/api.version)
+
+echo "Version: $VERSION"
+echo "GIT_COMMIT: $GIT_COMMIT"
+echo "BUILD_TIME: $BUILD_TIME"
+echo "GO_OS_ARCH: $GO_OS_ARCH"
+echo "API_VERSION: $API_VERSION"
+
+export LD_FLAGS="-X git.skogstorpet.nu/staffan/environ.GitCommit=$GIT_COMMIT \
+    -X git.skogstorpet.nu/staffan/environ.BuildTime=$BUILD_TIME \
+    -X git.skogstorpet.nu/staffan/environ.GoOsArch=$GO_OS_ARCH \
+    -X git.skogstorpet.nu/staffan/environ.Version=$VERSION \
+    -X git.skogstorpet.nu/staffan/environ.APIVersion=$API_VERSION"
+
+echo "BUILDING $PROJ_ROOT/.examples/server"
+go build -ldflags "$LD_FLAGS" -o $PROJ_ROOT/.examples/server $PROJ_ROOT/example/server/main.go
+
+echo "BUILDING $PROJ_ROOT/.examples/client"
+go build -ldflags "$LD_FLAGS" -o $PROJ_ROOT/.examples/client $PROJ_ROOT/example/client/main.go
+
+echo "Starting $PROJ_ROOT/.examples/server"
+${PROJ_ROOT}/.examples/server &
+spid=$!
+
+echo "Starting $PROJ_ROOT/.examples/client"
+$PROJ_ROOT/.examples/client &
+sleep 2
+echo Killing server
+kill $spid

+ 22 - 0
example/server/main.go

@@ -0,0 +1,22 @@
+package main
+
+import (
+	"net"
+
+	"git.skogstorpet.nu/staffan/environ"
+	"google.golang.org/grpc"
+)
+
+func main() {
+	lis, err := net.Listen("tcp", "127.0.0.1:12345")
+	if err != nil {
+		panic(err)
+	}
+	defer lis.Close()
+	server := grpc.NewServer()
+	environ.NewServer(server)
+	if err := server.Serve(lis); err != nil {
+		panic(err)
+	}
+
+}

+ 11 - 0
go.mod

@@ -0,0 +1,11 @@
+module git.skogstorpet.nu/staffan/environ
+
+go 1.16
+
+require (
+	golang.org/x/net v0.0.0-20210521195947-fe42d452be8f // indirect
+	golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1 // indirect
+	google.golang.org/genproto v0.0.0-20210521181308-5ccab8a35a9a // indirect
+	google.golang.org/grpc v1.38.0
+	google.golang.org/protobuf v1.26.0
+)

+ 123 - 0
go.sum

@@ -0,0 +1,123 @@
+cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
+github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
+github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
+github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
+github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
+github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
+github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
+github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
+github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
+github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
+github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
+github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
+github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
+github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
+github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
+github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
+github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
+github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
+github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
+golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
+golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
+golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
+golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
+golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
+golang.org/x/net v0.0.0-20210521195947-fe42d452be8f h1:Si4U+UcgJzya9kpiEUJKQvjr512OLli+gL4poHrz93U=
+golang.org/x/net v0.0.0-20210521195947-fe42d452be8f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
+golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1 h1:lCnv+lfrU9FRPGf8NeRuWAAPjNnema5WtBinMgs1fD8=
+golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
+golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
+golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
+golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
+golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
+google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
+google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
+google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
+google.golang.org/genproto v0.0.0-20210521181308-5ccab8a35a9a h1:FaCiYXNZoBH/gnmVjMAHgOgdmpVVROBYOA+qCOHh6Hc=
+google.golang.org/genproto v0.0.0-20210521181308-5ccab8a35a9a/go.mod h1:P3QM42oQyzQSnHPnZ/vqoCdDmzH28fzWByN9asMeM8A=
+google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
+google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
+google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
+google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
+google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
+google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0=
+google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
+google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
+google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
+google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
+google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
+google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
+google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
+google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

+ 22 - 0
scripts/gen_grpc.sh

@@ -0,0 +1,22 @@
+#! /bin/bash
+
+# SPDX-FileCopyrightText: 2021 Staffan Olsson <naffatso@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+
+# Generate the gRPC code
+export PATH="$PATH:$(go env GOPATH)/bin"
+PROJ_ROOT="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"/..
+
+protogen --stdin <<EOF
+protoc_path: $PROJ_ROOT/.tools/bin/protoc
+include_paths:
+  - $PROJ_ROOT
+go_opts:
+  - paths=source_relative
+go_plugins:
+  - grpc
+go_out: $PROJ_ROOT
+paths:
+  - $PROJ_ROOT
+EOF

+ 21 - 0
scripts/install_protoc.sh

@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# SPDX-FileCopyrightText: 2021 Staffan Olsson <naffatso@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+
+# Installs protoc into .bin
+# Install protoc-gen-go and protoc-go-inject-tag into GOBIN
+PROJ_ROOT="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"/..
+mkdir -p $PROJ_ROOT/.tools
+PB_REL="https://github.com/protocolbuffers/protobuf/releases"
+PB_VER=3.14.0
+pushd $PROJ_ROOT/.tools
+curl -LO $PB_REL/download/v$PB_VER/protoc-$PB_VER-linux-x86_64.zip
+unzip protoc-$PB_VER-linux-x86_64.zip
+go get -u github.com/golang/protobuf/protoc-gen-go
+go get -u github.com/favadi/protoc-go-inject-tag
+go get -u google.golang.org/grpc
+
+go install git.skogstorpet.nu/staffan/protogen@latest
+popd

+ 33 - 0
server.go

@@ -0,0 +1,33 @@
+package environ
+
+import (
+	context "context"
+	"runtime"
+
+	grpc "google.golang.org/grpc"
+)
+
+// Server implements the EnvironmentServer
+type Server struct {
+	UnimplementedEnvironmentSvcServer
+}
+
+// GetEnvironment responds with the information about the environment
+func (s *Server) GetEnvironment(context.Context, *Void) (*Environment, error) {
+	rsp := &Environment{
+		Version:    Version,
+		GitCommit:  GitCommit,
+		BuildTime:  BuildTime,
+		GoOsArch:   GoOsArch,
+		ApiVersion: Version,
+		GoVersion:  runtime.Version(),
+	}
+	return rsp, nil
+}
+
+// NewServer returns a new environ.Server
+func NewServer(grpcServer *grpc.Server) *Server {
+	s := &Server{}
+	RegisterEnvironmentSvcServer(grpcServer, s)
+	return s
+}