From 1619f58d782ae4de67a056757efbbdc91ce30367 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 22 Nov 2019 16:28:22 +0000 Subject: feat(tools): Add 'gotest' program to demonstrate pkgs.buildGo This is a tiny program that does nothing but exists to demonstrate pkgs.buildGo by building a program that depends on a local library as well as a protobuf definition. --- tools/gotest/default.nix | 27 +++++++++++++++++++++++++++ tools/gotest/lib.go | 11 +++++++++++ tools/gotest/main.go | 16 ++++++++++++++++ tools/gotest/test.proto | 9 +++++++++ 4 files changed, 63 insertions(+) create mode 100644 tools/gotest/default.nix create mode 100644 tools/gotest/lib.go create mode 100644 tools/gotest/main.go create mode 100644 tools/gotest/test.proto diff --git a/tools/gotest/default.nix b/tools/gotest/default.nix new file mode 100644 index 000000000000..4396cd9b47c9 --- /dev/null +++ b/tools/gotest/default.nix @@ -0,0 +1,27 @@ +# This file demonstrates how to make use of pkgs.buildGo. +# +# It introduces libraries and protobuf support, however gRPC support +# is not yet included. +# +# From the root of this repository this example can be built with +# `nix-build -A tools.gotest` +{ pkgs, ... }: + +let + inherit (pkgs) buildGo; + + somelib = buildGo.package { + name = "somelib"; + srcs = [ ./lib.go ]; + }; + + someproto = buildGo.proto { + name = "someproto"; + proto = ./test.proto; + }; + +in buildGo.program { + name = "gotest"; + srcs = [ ./main.go ]; + deps = [ somelib someproto ]; +} diff --git a/tools/gotest/lib.go b/tools/gotest/lib.go new file mode 100644 index 000000000000..0aeebb2aea69 --- /dev/null +++ b/tools/gotest/lib.go @@ -0,0 +1,11 @@ +package somelib + +import "fmt" + +func Name() string { + return "edef" +} + +func Greet(s string) string { + return fmt.Sprintf("Hello %s", s) +} diff --git a/tools/gotest/main.go b/tools/gotest/main.go new file mode 100644 index 000000000000..99218c077617 --- /dev/null +++ b/tools/gotest/main.go @@ -0,0 +1,16 @@ +// This program just exists to import some libraries and demonstrate +// that the build works, it doesn't do anything useful. +package main + +import ( + "fmt" + "somelib" + "someproto" +) + +func main() { + p := someproto.Person{ + Name: somelib.Name(), + } + fmt.Println(somelib.Greet(fmt.Sprintf("%v", p))) +} diff --git a/tools/gotest/test.proto b/tools/gotest/test.proto new file mode 100644 index 000000000000..76af63072be3 --- /dev/null +++ b/tools/gotest/test.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package someproto; + +import "google/protobuf/timestamp.proto"; + +message Person { + string name = 1; + google.protobuf.Timestamp last_updated = 2; +} -- cgit 1.4.1