versionfmt

package
v2.0.0-pre.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package versionfmt exposes functions to dynamically register formats used to parse Feature Versions.

Index

Constants

View Source
const (
	// MinVersion is a special package version which is always sorted first.
	MinVersion = "#MINV#"

	// MaxVersion is a special package version which is always sorted last.
	MaxVersion = "#MAXV#"
)

Variables

View Source
var (
	// ErrUnknownVersionFormat is returned when a function does not have enough
	// context to determine the format of a version.
	ErrUnknownVersionFormat = errors.New("unknown version format")

	// ErrInvalidVersion is returned when a function needs to validate a version,
	// but should return an error in the case where the version is invalid.
	ErrInvalidVersion = errors.New("invalid version")
)

Functions

func Compare

func Compare(format, versionA, versionB string) (int, error)

Compare is a helper function that will compare two versions with a given format and return an error if there are any failures.

func RegisterParser

func RegisterParser(name string, p Parser)

RegisterParser provides a way to dynamically register an implementation of a Parser.

If RegisterParser is called twice with the same name, the name is blank, or if the provided Parser is nil, this function panics.

func Valid

func Valid(format, version string) error

Valid is a helper function that will return an error if the version fails to validate with a given format.

Types

type Parser

type Parser interface {
	// Valid attempts to parse a version string and returns its success.
	Valid(string) bool

	// Compare parses two different version strings.
	// Returns 0 when equal, -1 when a < b, 1 when b < a.
	Compare(a, b string) (int, error)
}

Parser represents any format that can compare two version strings.

func GetParser

func GetParser(name string) (p Parser, exists bool)

GetParser returns the registered Parser with a provided name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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