environ

package module
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2023 License: MIT Imports: 13 Imported by: 5

README

environ

A simple lib to retrieve build time environment for client and server.

Usage

go get -u git.skogstorpet.nu/staffan/environ

The server should implement the EnvironmentSvc 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:


# 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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// 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

	// GoVersion is the current version of the go compiler
	GoVersion string
)
View Source
var EnvironmentSvc_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "environ.v1.EnvironmentSvc",
	HandlerType: (*EnvironmentSvcServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "GetEnvironment",
			Handler:    _EnvironmentSvc_GetEnvironment_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "pb/environ/v1/env.proto",
}

EnvironmentSvc_ServiceDesc is the grpc.ServiceDesc for EnvironmentSvc service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

View Source
var File_environ_v1_env_proto protoreflect.FileDescriptor

Functions

func GetBuildInfo

func GetBuildInfo(conn *grpc.ClientConn, timeout time.Duration) (clientEnv *Environment, serverEnv *Environment, err error)

GetBuildInfo uses an existing grpc connection to request the server eviron and returns that with the client environ.

func PrintBuildInfo

func PrintBuildInfo(out io.Writer, clientEnv, serverEnv *Environment)

PrintBuildInfo prints the environment for client and server, if they are defined

func RegisterEnvironmentSvcServer

func RegisterEnvironmentSvcServer(s grpc.ServiceRegistrar, srv EnvironmentSvcServer)

Types

type Environment

type Environment struct {
	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"`
	// contains filtered or unexported fields
}

func GetClientEnvironment added in v1.0.3

func GetClientEnvironment() *Environment

GetClientEnvironment returns the clients environment.

func (*Environment) Descriptor deprecated

func (*Environment) Descriptor() ([]byte, []int)

Deprecated: Use Environment.ProtoReflect.Descriptor instead.

func (*Environment) GetApiVersion

func (x *Environment) GetApiVersion() string

func (*Environment) GetBuildTime

func (x *Environment) GetBuildTime() string

func (*Environment) GetGitCommit

func (x *Environment) GetGitCommit() string

func (*Environment) GetGoOsArch

func (x *Environment) GetGoOsArch() string

func (*Environment) GetGoVersion

func (x *Environment) GetGoVersion() string

func (*Environment) GetVersion

func (x *Environment) GetVersion() string

func (*Environment) ProtoMessage

func (*Environment) ProtoMessage()

func (*Environment) ProtoReflect

func (x *Environment) ProtoReflect() protoreflect.Message

func (*Environment) Reset

func (x *Environment) Reset()

func (*Environment) String

func (x *Environment) String() string

type EnvironmentSvcClient

type EnvironmentSvcClient interface {
	GetEnvironment(ctx context.Context, in *Void, opts ...grpc.CallOption) (*Environment, error)
}

EnvironmentSvcClient is the client API for EnvironmentSvc service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type EnvironmentSvcServer

type EnvironmentSvcServer interface {
	GetEnvironment(context.Context, *Void) (*Environment, error)
	// contains filtered or unexported methods
}

EnvironmentSvcServer is the server API for EnvironmentSvc service. All implementations must embed UnimplementedEnvironmentSvcServer for forward compatibility

type Server

type Server struct {
	UnimplementedEnvironmentSvcServer
}

Server implements the EnvironmentServer

func NewServer

func NewServer(grpcServer *grpc.Server) *Server

NewServer returns a new environ.Server

func (*Server) GetEnvironment

func (s *Server) GetEnvironment(context.Context, *Void) (*Environment, error)

GetEnvironment responds with the information about the environment

type UnimplementedEnvironmentSvcServer

type UnimplementedEnvironmentSvcServer struct {
}

UnimplementedEnvironmentSvcServer must be embedded to have forward compatible implementations.

func (UnimplementedEnvironmentSvcServer) GetEnvironment

type UnsafeEnvironmentSvcServer added in v1.1.0

type UnsafeEnvironmentSvcServer interface {
	// contains filtered or unexported methods
}

UnsafeEnvironmentSvcServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to EnvironmentSvcServer will result in compilation errors.

type Void

type Void struct {
	// contains filtered or unexported fields
}

func (*Void) Descriptor deprecated

func (*Void) Descriptor() ([]byte, []int)

Deprecated: Use Void.ProtoReflect.Descriptor instead.

func (*Void) ProtoMessage

func (*Void) ProtoMessage()

func (*Void) ProtoReflect

func (x *Void) ProtoReflect() protoreflect.Message

func (*Void) Reset

func (x *Void) Reset()

func (*Void) String

func (x *Void) String() string

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL