gitinfo

package module
v0.0.0-...-1c25fbd Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2019 License: MIT Imports: 10 Imported by: 0

README

gitinfo

Get git repo metagata (lib) and generate gitinfo.json via go generate (cmd)

GoDoc codecov Build Status GoCard GitHub Release GitHub license

Requirements

git binary have to be in $PATH

Install

go get github.com/LeKovr/gitinfo/...

Usage

import "github.com/LeKovr/gitinfo"

func main() {
    data, err := gitinfo.New("sql/")
    if err != nil {
	return err
    }
    log.Printf("%#v\n",data)
}

Generate

//go:generate gitinfo sql/

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MkTime

func MkTime(in []byte, rv *time.Time) error

MkTime converts []byte to time.Time

func Modified

func Modified(path string, rv *time.Time) error

Modified fills rv with package last commit timestamp

func Repository

func Repository(path string, rv *string) error

Repository fills rv with package repo from git

func Version

func Version(path string, rv *string) error

Version fills rv with package version from git

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"`
}

Config holds all config vars

type GitInfo

type GitInfo struct {
	Version    string    `json:"version"`
	Repository string    `json:"repository"`
	Modified   time.Time `json:"modified"`
}

type Service

type Service struct {
	Config
	GI *GitInfo
}

GitInfo holds git repository metadata

func New

func New(cfg Config) *Service

New returns service object with config

Example
cfg := Config{}
// Fill config with default values
p := flags.NewParser(&cfg, flags.Default|flags.IgnoreUnknown)
_, err := p.Parse()
//        require.NoError(ss.T(), err)

var gi GitInfo
err = New(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, "LeKovr/gitinfo.git"),
)
Output:

true
true
true

func (Service) Make

func (srv Service) Make(path string, gi *GitInfo) error

Make prepares GitInfo data

func (Service) Read

func (srv Service) Read(fs http.FileSystem, path string) (*GitInfo, error)

Red reads GitInfo data from file

func (Service) Write

func (srv Service) Write(path string, gi *GitInfo) error

Write saves GitInfo data to file, prepare it if none given

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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