semver

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

README

Semver

A SemVer Package is a package that implements the Semantic Versioning (SemVer) specification. SemVer is a widely adopted standard for versioning software libraries and applications, making it easier for developers to understand when and what changes have been made to a package.



Installation

go get go.nandlabs.io/commons/semver

Features

  • Adheres to the SemVer 2.0.0 specification
  • Easy to use API for parsing, comparing and generating SemVer versions
  • Supports pre-release and build metadata
  • Written in modern Golang and follows best practices

Usage

Here is an example of how to use the SemVer package in a Golang project:

package main

import (
	"fmt"
	"go.nandlabs.io/commons/semver"
)

func main() {
	version, err := semver.Parse("v1.2.3")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("Major :: %d", version.major)
	fmt.Printf("Minor :: %d", version.minor)
	fmt.Printf("Patch :: %d", version.patch)
	
	metadataVersion, err := semver.Parse("v1.2.3-SNAPSHOT")
	if err != nil {
		fmt.Println(err)
    }
	fmt.Printf("Major :: %d", metadataVersion.major)
	fmt.Printf("Minor :: %d", metadataVersion.minor)
	fmt.Printf("Patch :: %d", metadataVersion.patch)
	fmt.Printf("Pre-Release :: %s", metadataVersion.preRelease)
}

Documentation

Index

Constants

View Source
const (
	RegexSemver     = `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$`
	RegexPreRelease = `^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)`
)

Variables

This section is empty.

Functions

func CompareRaw

func CompareRaw(ver1, ver2 string) (int, error)

CompareRaw returns three values -1, 0, +1 -1 denotes ver1 < ver2 0 denotes invalid input +1 denotes ver1 > ver2

Types

type SemVer

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

func Parse

func Parse(input string) (*SemVer, error)

func (*SemVer) Compare

func (s *SemVer) Compare(v *SemVer) (int, error)

Compare returns three values -1, 0, +1 -1 denotes ver1 < ver2 0 denotes invalid input +1 denotes ver1 > ver2

func (*SemVer) IsPreRelease

func (s *SemVer) IsPreRelease() bool

func (*SemVer) NextMajor

func (s *SemVer) NextMajor() *SemVer

func (*SemVer) NextMinor

func (s *SemVer) NextMinor() *SemVer

func (*SemVer) NextPatch

func (s *SemVer) NextPatch() *SemVer

func (*SemVer) PreRelease

func (s *SemVer) PreRelease(tag string) *SemVer

func (*SemVer) String

func (s *SemVer) String() string

Jump to

Keyboard shortcuts

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