vendor

package module
v0.0.0-...-b01a19e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2018 License: MIT Imports: 2 Imported by: 0

README

vendor

Build Status GoDoc

Golang package to track build and vendor information of packages within a Go project.

Building

This code is part of the greater golang community. It can be retrieved, compiled, tested, and installed using the go tool. In order to use this, you will need a correctly setup golang environment.

shell$ go get github.com/weingart/vendor

See GoDoc for more information.

Documentation

Overview

Package vendor provides methods to register vendor'd code information as well as build information for a golang binary.

Within each vendor'd copy of a package a single file is created, usually called '$dir/vendor.go' within the package of the vendor'd code that looks something like:

package vendor-code

import "github.com/weingart/vendor"

func init() {
	vendor.Add(&vendor.Info{
		"git-repo": "github.com/vendor/repo",
		"git-sha":  "9e69b5e2e8d4d042f67d9b24f0f69ffb3ab35687",
		"git-tag":  "sometag",
	})
}

Within the packe github.com/weingart/vendor, there are variables that can set during the build via the -ldflags flags. These variables can be overridden using something like:

SHA=$(git rev-parse HEAD)
go install -a -ldflags "-X github.com/weingart/vendor.buildSHA ${SHA}" example

The following variables are available to be set:

buildSHA
buildTag
buildUser
buildTime
buildComment

In order to be able to introspect the values within a running server, the information is registered with the expvar package. They can also be retrieved by using the appropriate vendor.Get*() functions. For example:

package main

import (
	_ "expvar"
	"fmt"
	"github.com/weingart/vendor"
	"net/http"
)

func main() {
	fmt.Println(vendor.GetInfo())
	http.ListenAndServe(":8080", nil)
}

The information can be found by going to: http://localhost:8080/debug/vars

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(v *Info)

Types

type BuildInfo

type BuildInfo struct {
	SHA     string `json:"sha"`
	Tag     string `json:"tag"`
	User    string `json:"user"`
	Time    string `json:"time"`
	Comment string `json:"comment"`
}

func GetBuildInfo

func GetBuildInfo() *BuildInfo

type Info

type Info map[string]string

func GetInfo

func GetInfo() []Info

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL