Documentation ¶
Overview ¶
Package gitinfo used for generate and read gitinfo.json file which contains git repository data like this:
{ "version": "v0.33-1-g4f4575a", "repository": "https://github.com/pgmig-sql/pgmig.git", "modified": "2019-12-24T02:44:51+03:00" }
This file is intended to be included in embedded FS
Index ¶
- Variables
- func MkTime(in []byte, rv *time.Time) error
- type Config
- type File
- type FileSystem
- type GitInfo
- type Service
- func (srv Service) Make(path string, gi *GitInfo) error
- func (srv Service) Modified(path string, rv *time.Time) error
- func (srv Service) Read(fs FileSystem, path string) (*GitInfo, error)
- func (srv Service) ReadOrMake(fs FileSystem, path string) (*GitInfo, error)
- func (srv Service) Repository(path string, rv *string) error
- func (srv Service) Version(path string, rv *string) error
- func (srv Service) Write(path string, gi *GitInfo) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrPathMustNotBeEmpty raised if given path is empty ErrPathMustNotBeEmpty = errors.New("Path must not be empty") // ErrPathMustBeDir raised if given path is not directory ErrPathMustBeDir = errors.New("Path must be a directory") )
Functions ¶
Types ¶
type Config ¶
type Config struct { Debug bool `long:"debug" description:"Show debug data"` File string `long:"file" default:"gitinfo.json" description:"GitInfo json filename"` GitBin string `long:"gitbin" default:"git" description:"Git binary name"` // Root may be hardcoded if app uses embedded FS, so do not showed in help Root string }
Config holds all config vars
type FileSystem ¶ added in v0.11.3
FileSystem holds all of used filesystem access methods
type GitInfo ¶
type GitInfo struct { Version string `json:"version"` Repository string `json:"repository"` Modified time.Time `json:"modified"` }
GitInfo holds git repository metadata
type Service ¶
type Service struct { Config Config Log logr.Logger GI *GitInfo // contains filtered or unexported fields }
Service holds service data
func New ¶
New returns service object with config
Example ¶
log := genericr.New(func(e genericr.Entry) { fmt.Fprintln(os.Stderr, e.String()) }) cfg := gitinfo.Config{} // Fill config with default values p := flags.NewParser(&cfg, flags.Default|flags.IgnoreUnknown) _, err := p.Parse() if err != nil { log.Error(err, "Config") os.Exit(1) } var gi gitinfo.GitInfo err = gitinfo.New(log, cfg).Make("cmd/", &gi) if err != nil { fmt.Printf("%#v\n", err) } fmt.Printf("%v\n%v\n%v\n", gi.Modified != time.Time{}, gi.Version != "", strings.HasSuffix(gi.Repository, "pgmig/gitinfo.git"), )
Output: true true true
func (Service) Make ¶
Make prepares GitInfo data
Example ¶
package main import ( "fmt" "os" "strings" "time" "github.com/wojas/genericr" "github.com/pgmig/gitinfo" ) func main() { log := genericr.New(func(e genericr.Entry) { fmt.Fprintln(os.Stderr, e.String()) }) gi := gitinfo.GitInfo{} err := gitinfo.New(log, gitinfo.Config{GitBin: "git"}).Make("cmd/", &gi) if err != nil { fmt.Printf("%#v\n", err) } fmt.Printf("%v\n%v\n%v\n", gi.Modified != time.Time{}, gi.Version != "", strings.HasSuffix(gi.Repository, "pgmig/gitinfo.git"), ) }
Output: true true true
func (Service) Read ¶
func (srv Service) Read(fs FileSystem, path string) (*GitInfo, error)
Read reads GitInfo data from file
func (Service) ReadOrMake ¶ added in v0.11.3
func (srv Service) ReadOrMake(fs FileSystem, path string) (*GitInfo, error)
ReadOrMake reads GitInfo data from file or makes it from git on the fly
func (Service) Repository ¶ added in v0.12.1
Repository fills rv with package repo from git
Click to show internal directories.
Click to hide internal directories.