This package helps to include version info to your go application.
Make sure that Go is installed on your computer. Type the following command in your terminal:
go get github.com/olenindenis/go-version
After it the package is ready to use.
Add following line in your *.go
file:
import "github.com/olenindenis/go-version"
Before running your code, you need to run the command:
make build
or create your own as shown in the example:
go build -ldflags=${linker_flags} -o=./main ./main.go
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/olenindenis/go-version"
)
func main() {
http.HandleFunc("/version", func (w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(version.Info())
})
log.Fatal(http.ListenAndServe(":8080", nil))
}