project

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package project provides metadata and VCS information of a project.

Index

Constants

View Source
const (
	// ErrDeriveVCSInformation indicates that the derivation of VCS version information failed.
	ErrDeriveVCSInformation = wErr.ErrString("failed to derive VCS version information")

	// ErrDetectProjectRootDirPath indicates that the detection of a project root directory path failed.
	ErrDetectProjectRootDirPath = wErr.ErrString("failed to detect project root directory path")

	// ErrDetermineGoModuleInformation indicates that a determination of Go module information failed.
	ErrDetermineGoModuleInformation = wErr.ErrString("failed to determine Go module information")

	// ErrPathNotRelative indicates that a path is not relative.
	ErrPathNotRelative = wErr.ErrString("path is not relative")
)
View Source
const (
	// DefaultBaseOutputDir is the default base output directory relative to Options.RootDirPathAbs for compile, test
	// and production artifacts as well as distribution bundles, static web files or metric/statistic reports.
	DefaultBaseOutputDir = "out"

	// DefaultVersion is the default version for a project vcs.Repository.
	DefaultVersion = "v0.0.0"
)
View Source
const (
	// GoModuleVersionLatest is the "version query suffix" for the latest version of a Go module.
	//
	// See https://golang.org/ref/mod#version-queries for more details.
	GoModuleVersionLatest = "latest"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrProject

type ErrProject struct {
	// Err is a wrapped error.
	Err error
	// Kind is the error kind.
	Kind error
}

ErrProject represents a project error.

func (*ErrProject) Error

func (e *ErrProject) Error() string

func (*ErrProject) Is

func (e *ErrProject) Is(err error) bool

Is enables usage of errors.Is() to determine the kind of error that occurred.

func (*ErrProject) Unwrap

func (e *ErrProject) Unwrap() error

Unwrap returns the underlying error for usage with errors.Unwrap().

type GoModuleID

type GoModuleID struct {
	// IsLatest indicates whether the Go module version uses GoModuleVersionLatest as "version query suffix".
	IsLatest bool

	// Path is the canonical name for a module, declared with the module directive in the module's go.mod file.
	//
	// References
	//
	//   (1) https://golang.org/ref/mod#module-path
	//   (2) https://golang.org/ref/mod#go-mod-file-module
	//   (3) https://golang.org/ref/mod#glos-go-mod-file
	Path string

	// Version identifies an immutable snapshot of a module starting with the letter "v", followed by a semantic
	// version.
	// Note that a nil value is resolved using GoModuleVersionLatest s "version query suffix".
	//
	// References
	//
	//   (1) https://golang.org/ref/mod#versions
	//   (2) https://golang.org/ref/mod#version-queries
	//   (3) https://semver.org/spec/v2.0.0.html
	//   (4) https://golang.org/cmd/go/#hdr-Pseudo_versions
	//   (5) https://blog.golang.org/publishing-go-modules
	Version *semver.Version
}

GoModuleID stores partial information to identify a Go module.

See https://golang.org/ref/mod#modules-overview for more details.

func (GoModuleID) String

func (gm GoModuleID) String() string

type Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

Metadata represents information about a project.

func New

func New(opts ...Option) (*Metadata, error)

New creates new project metadata.

The absolute path to the root directory is automatically set based on the current working directory while the Go module name is determined using the runtime/debug package.

The project version is derived from the vcs.Repository if not of type vcs.KindNone. The currently only supported vcs.Kind is vcs.KindGit. To set the vcs.Kind the WithVCSKind() project Option can be used.

If any error occurs nil is returned along with an error of type *ErrProject.

func (Metadata) Options

func (m Metadata) Options() Options

Options returns the project Options.

type Option

type Option func(*Options)

Option is a project option.

func WithBaseOutputDir

func WithBaseOutputDir(dir string) Option

WithBaseOutputDir sets the base output directory.

func WithDefaultVersion

func WithDefaultVersion(defaultVersion string) Option

WithDefaultVersion set the project default verion.

func WithDisplayName

func WithDisplayName(name string) Option

WithDisplayName sets the project display name.

func WithGoModule

func WithGoModule(module *GoModuleID) Option

WithGoModule sets the project Go module.

func WithName

func WithName(name string) Option

WithName sets the project name.

func WithVCSKind

func WithVCSKind(kind vcs.Kind) Option

WithVCSKind sets the vcs.Kind of the project vcs.Repository.

type Options

type Options struct {
	// BaseOutputDir is the base project output directory, relative to RootDirPathAbs, for compile, test and production
	// artifacts as well as distribution bundles, static web files or metric/statistic reports.
	BaseOutputDir string

	// DefaultVersion is the default project version.
	DefaultVersion string

	// DisplayName is the project display name.
	DisplayName string

	// GoModule is the project Go module.
	GoModule *GoModuleID

	// Name is the project name.
	Name string

	// Repository is the project repository.
	Repository vcs.Repository

	// RootDirPathAbs is the absolute path to the project root directory.
	RootDirPathAbs string

	// VCSKind is the VCS kind of the project Repository.
	VCSKind vcs.Kind
}

Options stores project options.

Directories

Path Synopsis
vcs
Package vcs provides packages utilities to interact with version control systems.
Package vcs provides packages utilities to interact with version control systems.
git
Package git provides VCS utility functions to interact with Git repositories.
Package git provides VCS utility functions to interact with Git repositories.
none
Package none provides a nonexistent repository.
Package none provides a nonexistent repository.

Jump to

Keyboard shortcuts

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