Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
Add version to plugin
Browse files Browse the repository at this point in the history
version is set via ldflags at compile time. It should be JSON encoded
plugin.VersionType. If it does not unmarshal, the plugin version will be
left empty.

An example:
go build -ldflags '-X main.version={"Major":99,"Minor":88,"Build":77}'
  • Loading branch information
Andrew Poydence committed Dec 13, 2017
1 parent 99f919e commit 1bb6d46
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/json"
"log"
"os"

Expand Down Expand Up @@ -30,9 +31,20 @@ func (c CFSyslogCLI) Run(conn plugin.CliConnection, args []string) {
}
}

// version is set via ldflags at compile time. It should be JSON encoded
// plugin.VersionType. If it does not unmarshal, the plugin version will be
// left empty.
var version string

func (c CFSyslogCLI) GetMetadata() plugin.PluginMetadata {
var v plugin.VersionType
// Ignore the error. If this doesn't unmarshal, then we want the default
// VersionType.
_ = json.Unmarshal([]byte(version), &v)

return plugin.PluginMetadata{
Name: "CF Syslog CLI Plugin",
Name: "CF Syslog CLI Plugin",
Version: v,
Commands: []plugin.Command{
{
Name: "drains",
Expand Down

0 comments on commit 1bb6d46

Please sign in to comment.