Skip to content

ryanuber/go-semver

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

go-semver Build Status

Semantic Versioning implementation in go.

API

func Compare(v1 *SemVer, comp string, v2 *SemVer) bool
func CompareString(v1 *SemVer, in string) (bool, error)
type SemVer
    func New(major, minor, patch, preRel, build string) (*SemVer, error)
    func NewFromString(vstr string) (*SemVer, error)
    func (s *SemVer) BaseString() string
    func (s *SemVer) String() string

Examples

package main

import (
    "fmt"
    "github.com/ryanuber/go-semver"
)

func main() {
    v1, err := semver.NewFromString("3.12.9")
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    v2, err := semver.NewFromString("3.12.8-alpha1+727d41c")
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    // Compare two semver objects
    res := semver.Compare(v1, ">", v2)
    fmt.Printf("%s > %s: %#v\n", v1.String(), v2.String(), res)

    // Compare a semver object to a string
    res, err = semver.CompareString(v1, "> 3.2.8")
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    fmt.Printf("%s > 3.2.8: %#v\n", v1.String(), res)

    // Compare multiple strings
    res, err = semver.CompareString(v1, "> 3.2.8, < 4.0.0")
    if err != nil {
        fmt.Println(err.Error())
        return
    }
    fmt.Printf("%s > 3.2.8 and < 4.0.0: %#v\n", v1.String(), res)
}

About

Semantic versioning (semver.org) for golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages