package version

import (
	"fmt"
	"runtime"
)

// GitHash is the git hash and the value will be injected when compile stage.
// see: build scripts
var (
	GitHash = "Unknown"
	GitRef  = "None"
	version = &Info{}
)

type Info struct {
	GitHash   string `json:"gitHash"`
	GitRef    string `json:"gitRef"`
	GoVersion string `json:"goVersion"`
}

func newVersionInfo() *Info {
	return &Info{
		GitHash:   GitHash,
		GitRef:    GitRef,
		GoVersion: runtime.Version(),
	}
}

func init() {
	version = newVersionInfo()
}

func PrintInfo() string {
	return fmt.Sprintf(`Git Commit Hash: %s
Git Branch: %s
Go Version: %s`, version.GitHash, version.GitRef, version.GoVersion)
}

func Version() *Info {
	return version
}
