Waylon  Bruen

Waylon Bruen

1654748040

Govvv: "go Build" Wrapper to Add Version info To Golang Applications

govvv

The simple Go binary versioning tool that wraps the go build command.

68747470733a2f2f636c2e6c792f3055326d34343176333932512f696e74726f2d312e676966

Stop worrying about -ldflags and go get github.com/ahmetb/govvv now.

Build Variables

VariableDescriptionExample
main.GitCommitshort commit hash of source tree0b5ed7a
main.GitBranchcurrent branch name the code is built offmaster
main.GitStatewhether there are uncommitted changesclean or dirty
main.GitSummaryoutput of git describe --tags --dirty --alwaysv1.0.0
v1.0.1-5-g585c78f-dirty
fbd157c
main.BuildDateRFC3339 formatted UTC date2016-08-04T18:07:54Z
main.Versioncontents of ./VERSION file, if exists, or the value passed via the -version option2.0.0

Using govvv is easy

Just add the build variables you want to the main package and run:

old:sparkles: new :sparkles:
go buildgovvv build
go installgovvv install

Version your app with govvv

Create a VERSION file in your build root directory and add a Version variable to your main package.

Do you have your own way of specifying Version? No problem:

govvv lets you specify custom -ldflags

Your existing -ldflags argument will still be preserved:

govvv build -ldflags "-X main.BuildNumber=$buildnum" myapp

and the -ldflags constructed by govvv will be appended to your flag.

Don’t want to depend on govvv? It’s fine!

You can just pass a -print argument and govvv will just print the go build command with -ldflags for you and will not execute the go tool:

$ govvv build -print
go build \
    -ldflags \
    "-X main.GitCommit=57b9870 -X main.GitBranch=dry-run -X main.GitState=dirty -X main.Version=0.1.0 -X main.BuildDate=2016-08-08T20:50:21Z"

Still don’t want to wrap the go tool? Well, try -flags to retrieve the LDFLAGS govvv prepares:

$ go build -ldflags="$(govvv -flags)"

Want to use a different package?

You can pass a -pkg argument with the full package name, and govvv will set the build variables in that package instead of main. For example:

# build with govvv
$ govvv build -pkg github.com/myacct/myproj/mypkg

# build with go
$ go build -ldflags="$(govvv -flags -pkg $(go list ./mypkg))"

Want to use a different version?

You can pass a -version argument with the desired version, and govvv will use the specified version instead of obtaining it from the ./VERSION file. For example:

# build with govvv
$ govvv build -version 1.2.3

# build with go
$ go build -ldflags="$(govvv -flags -version 1.2.3)"

Try govvv today

$ go get github.com/ahmetb/govvv

Author: Ahmetb
Source Code: https://github.com/ahmetb/govvv 
License: Apache-2.0 license

#go #golang #version 

What is GEEK

Buddha Community

Govvv: "go Build" Wrapper to Add Version info To Golang Applications
Waylon  Bruen

Waylon Bruen

1654748040

Govvv: "go Build" Wrapper to Add Version info To Golang Applications

govvv

The simple Go binary versioning tool that wraps the go build command.

68747470733a2f2f636c2e6c792f3055326d34343176333932512f696e74726f2d312e676966

Stop worrying about -ldflags and go get github.com/ahmetb/govvv now.

Build Variables

VariableDescriptionExample
main.GitCommitshort commit hash of source tree0b5ed7a
main.GitBranchcurrent branch name the code is built offmaster
main.GitStatewhether there are uncommitted changesclean or dirty
main.GitSummaryoutput of git describe --tags --dirty --alwaysv1.0.0
v1.0.1-5-g585c78f-dirty
fbd157c
main.BuildDateRFC3339 formatted UTC date2016-08-04T18:07:54Z
main.Versioncontents of ./VERSION file, if exists, or the value passed via the -version option2.0.0

Using govvv is easy

Just add the build variables you want to the main package and run:

old:sparkles: new :sparkles:
go buildgovvv build
go installgovvv install

Version your app with govvv

Create a VERSION file in your build root directory and add a Version variable to your main package.

Do you have your own way of specifying Version? No problem:

govvv lets you specify custom -ldflags

Your existing -ldflags argument will still be preserved:

govvv build -ldflags "-X main.BuildNumber=$buildnum" myapp

and the -ldflags constructed by govvv will be appended to your flag.

Don’t want to depend on govvv? It’s fine!

You can just pass a -print argument and govvv will just print the go build command with -ldflags for you and will not execute the go tool:

$ govvv build -print
go build \
    -ldflags \
    "-X main.GitCommit=57b9870 -X main.GitBranch=dry-run -X main.GitState=dirty -X main.Version=0.1.0 -X main.BuildDate=2016-08-08T20:50:21Z"

Still don’t want to wrap the go tool? Well, try -flags to retrieve the LDFLAGS govvv prepares:

$ go build -ldflags="$(govvv -flags)"

Want to use a different package?

You can pass a -pkg argument with the full package name, and govvv will set the build variables in that package instead of main. For example:

# build with govvv
$ govvv build -pkg github.com/myacct/myproj/mypkg

# build with go
$ go build -ldflags="$(govvv -flags -pkg $(go list ./mypkg))"

Want to use a different version?

You can pass a -version argument with the desired version, and govvv will use the specified version instead of obtaining it from the ./VERSION file. For example:

# build with govvv
$ govvv build -version 1.2.3

# build with go
$ go build -ldflags="$(govvv -flags -version 1.2.3)"

Try govvv today

$ go get github.com/ahmetb/govvv

Author: Ahmetb
Source Code: https://github.com/ahmetb/govvv 
License: Apache-2.0 license

#go #golang #version 

Hermann  Frami

Hermann Frami

1654409220

Serverless Go Builds: Makes Building Go with Serverless Easy!

Serverless Go Builds 

A Serverless v1.x plugin to making building Go easy!

Use your serverless.yml file as your build script, allowing specifying public functions or .go files as your entry points. Also can start other serverless plugins before running tests, and of course properly packages the built binary for upload (by default even individually packages each binary for increased performance!).

Features

  • Runs build for all go files listed as handlers (no separate build script!)
  • Specify go files or Public Functions directly (or continue to use path to binary)
    • Allows specifying packageName.FunctionName as function handler
  • Runs go tests
  • Can start serverless plugins before tests
    • eg: S3 or Dynalite test server - these can initialize resources based on yaml file
  • Individually packages each function for minimum lambda code size
    • Instead of sending one zip up with all binaries
  • Heavily customizable!
    • Doesn't even have to build Go!

Installation

npm install --save serverless-go-build

Usage

  • serverless build : Builds all Go binaries listed as function handlers
  • serverless build --function getWidget : Builds specific Go binaries
  • serverless test : Runs tests specified in serverless.yml
    • Passes in Environment variables GO_TEST=serverless and stage=testing

serverless deploy will not run the builds - run serverless build first.

Example serverless.yml

The below is a full serverless.yml example - however the only unique parts are:

  • custom.go-build - Location of custom overrides (see below)
  • package - Optionally specify individually: true for individual packaging
  • functions.{yourFunction}.handler - Specify your handler as .go file or module.PublicFunction
service: myService
plugins:
  - serverless-go-build
custom:
  go-build:
    # Example where we start "serverless-dynalite" prior to testing
    testPlugins:
      - dynalite:start
    # Run tests defined in endpoints module/folder
    tests:
      - ./endpoints
provider:
  name: aws
  runtime: go1.x
  stage: ${opt:stage, 'testing'}
package:
  individually: true
  # No need to include / exclude globally as each function
  # specifies it's include / exclude
functions:
  getWidget:
    # In this case this file must be a main package with main()
    handler: entrypoints/widget/get.go
    name: myService-${self:provider.stage}-getWidget
    events:
      - http:
          path: widget
          method: get
  postWidget:
    # In this case this file must be a main package with main()
    handler: entrypoints/widget/post.go
    name: myService-${self:provider.stage}-postWidget
    events:
      - http:
          path: widget
          method: post
  getPiece:
    # Shows how to call into a modules public function
    handler: piece.GetPiece
    name: myService-${self:provider.stage}-postWidget
    events:
      - http:
          path: widget
          method: post

Customization

You can override any of these fields inside of custom.go-build:

{
  // Prefix used for building for AWS
  awsbuildPrefix: 'GOOS=linux ',
  // Build command - followed by bin dest and input path
  buildCmd: `go build -ldflags="-s -w" -o %2 %1`,
  // Test command - followed by value in tests array below
  testCmd: `stage=testing GO_TEST=serverless go test %1`,
  // Path to store build results
  binPath: 'bin',
  // Runtime to require
  runtime: "go1.x",
  // The path to aws-lambda-go/lambda - autogenerated include in main.go
  // (needed when referring to module/PubFunction)
  pathToAWSLambda: "github.com/aws/aws-lambda-go/lambda",
  // Path to put generated main.go files (module/PubFunction)
  generatedMainPath: "generatedEntrypoints",
  // Location of go path - needed for (module/PubFunction)
  // Must point fully to the /src segment of the path
  // (By default pulls it from $GOPATH)
  goPath: undefined,
  // Pass this to minimize the package uploaded to just the binary
  // for that endpoint
  minimizePackage: true,
  // Test plugins to start before running 
  testPlugins: [],
  // Delay in milliseconds between starting plugins and starting tests
  testStartDelay: 0,
  // Array of tests to run
  tests: [],
}

Coming Soon

Will support in the future:

  • serverless test command supporting running individual test
  • Building locally vs for AWS

Important Notes

  • If you override package for a function you must include the bin file
    • We do not override package or add to it if you specify it explicitly

Author: Sean9keenan
Source Code: https://github.com/sean9keenan/serverless-go-build 
License: MIT license

#serverless #go #golang 

Elian  Harber

Elian Harber

1654567560

Colorgo: Colorize (highlight) `go Build` Command Output

colorgo

colorgo is a wrapper to go command that colorizes output from go build and go test.

Installation

go get -u github.com/songgao/colorgo

Usage

colorgo build

alias

colorgo changes nothing to sub-commands other than go build. So you can optionally define alias in your shell conf so that go build always prints colorized error message:

bash: ~/.bashrc

alias go=colorgo

fish-shell: ~/.config/fish/config.fish

alias go colorgo

Author: Songgao
Source Code: https://github.com/songgao/colorgo 
License: BSD 3-Clause License

#go #golang 

Let's Go Build a Bot (Part 11)

In January, our #WednesdayStreams returned with “Let’s Go Build a Bot” and your host Dom Davis! We returned in February, and now for your viewing pleasure, again, March brings Dom & GoLang.

We explored the GoLang programming language, using Docker to containerise the service and then Amazon’s AWS ECR, ECS & Fargate to get each Docker tag deployed.

This Bot is a nor(DEV): project, designed to replace the current “dumb” implementation - it will provide event marketing, interaction, and a StackOverflow-esque Q&A service on our Discord.

So, we return in February to see how far we can get. This year we’re going to host a range of streams and events around this Bot! Keep those eye peeled and why not get involved? Wanna build a part of the hive mind? A discreet micro-service? The mobile app? Some ML? Give us a shout!


About your Host

Dom Davis is a veteran of The City and a casualty of The Financial Crisis. Not content with bringing the world to its knees he then went off to help break the internet before winding up in Norfolk where he messes about doing development and devops. Dom has been writing code since his childhood sometime in the last millennium – he hopes some day to become good at it.

Dom is an enthusiastic and impassioned speaker [read: he gabbles] who uses a blend of irreverent sarcasm and flippant humour to bring complex subjects to a broad audience. Whether or not they understand him is up for debate, but he likes to believe they do.


About Norfolk Developers

You might want to try something new or wish to take your software development up to the next level. We want to jump into the detail and bring you practical value. We want to make it easy for you to access knowledge, progress and prosper in the highly specialised and valuable field of software engineering.

Our community goes beyond our regular events, we’re a thriving support network. Our membership include those that are just starting out, juniors, seniors, and the curious.

Read more at https://www.norfolkdevelopers.com/

#golang #docker #aws