github.com/blend/go-sdk@v1.20220411.3/semver/validators.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package semver 9 10 import "github.com/blend/go-sdk/ex" 11 12 // GreaterOrEqualTo returns a validator that enforces input versions 13 // are greater than or equal to a given version. 14 // 15 // Strictly speaking, it returns an error if an input version is 16 // less than the given version. 17 func GreaterOrEqualTo(version string) func(string) error { 18 compiled, err := NewVersion(version) 19 if err != nil { 20 panic(err) 21 } 22 return func(compare string) error { 23 compareCompiled, err := NewVersion(compare) 24 if err != nil { 25 return err 26 } 27 if compiled.LessThan(compareCompiled) { 28 return ex.New(ErrConstraintFailed, ex.OptMessagef("greater than or equal to: %v, compare: %s", version, compare)) 29 } 30 return nil 31 } 32 }