Documentation
¶
Overview ¶
Package version is a convenience utility that provides SDK consumers with a ready-to-use version command that produces apps versioning information based on flags passed at compile time.
Configure the version command ¶
The version command can be just added to your cobra root command. At build time, the variables Name, Version, Commit, and BuildTags can be passed as build flags as shown in the following example:
go build -X github.com/Dipper-Labs/Dipper-Protocol/version.Name=dip \ -X github.com/Dipper-Labs/Dipper-Protocol/version.ServerName=dipd \ -X github.com/Dipper-Labs/Dipper-Protocol/version.ClientName=dipcli \ -X github.com/Dipper-Labs/Dipper-Protocol/version.Version=1.0 \ -X github.com/Dipper-Labs/Dipper-Protocol/version.Commit=f0f7b7dab7e36c20b757cebce0e8f4fc5b95de60 \ -X "github.com/Dipper-Labs/Dipper-Protocol/version.BuildTags=linux darwin amd64"
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Name = "" ServerName = "<appd>" ClientName = "<appcli>" Version = "" Commit = "" BuildTags = "" AppVersion = uint64(0) )
View Source
var Cmd = &cobra.Command{ Use: "version", Short: "Print the app version", RunE: func(_ *cobra.Command, _ []string) error { verInfo := NewInfo() if !viper.GetBool(flagLong) { fmt.Printf("%s-%d\n", verInfo.Version, verInfo.AppVersion) return nil } var bz []byte var err error switch viper.GetString(cli.OutputFlag) { case "json": bz, err = json.Marshal(verInfo) default: bz, err = yaml.Marshal(&verInfo) } if err != nil { return err } _, err = fmt.Println(string(bz)) return err }, }
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct { Name string `json:"name" yaml:"name"` ServerName string `json:"server_name" yaml:"server_name"` ClientName string `json:"client_name" yaml:"client_name"` Version string `json:"version" yaml:"version"` AppVersion uint64 `json:"app_version" yaml:"app_version"` GitCommit string `json:"commit" yaml:"commit"` BuildTags string `json:"build_tags" yaml:"build_tags"` GoVersion string `json:"go" yaml:"go"` }
Click to show internal directories.
Click to hide internal directories.