gonum.org/v1/gonum@v0.14.0/version.go (about) 1 // Copyright ©2019 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gonum 6 7 import ( 8 "fmt" 9 "runtime/debug" 10 ) 11 12 const root = "gonum.org/v1/gonum" 13 14 // Version returns the version of Gonum and its checksum. The returned 15 // values are only valid in binaries built with module support. 16 // 17 // If a replace directive exists in the Gonum go.mod, the replace will 18 // be reported in the version in the following format: 19 // 20 // "version=>[replace-path] [replace-version]" 21 // 22 // and the replace sum will be returned in place of the original sum. 23 // 24 // The exact version format returned by Version may change in future. 25 func Version() (version, sum string) { 26 b, ok := debug.ReadBuildInfo() 27 if !ok { 28 return "", "" 29 } 30 for _, m := range b.Deps { 31 if m.Path == root { 32 if m.Replace != nil { 33 switch { 34 case m.Replace.Version != "" && m.Replace.Path != "": 35 return fmt.Sprintf("%s=>%s %s", m.Version, m.Replace.Path, m.Replace.Version), m.Replace.Sum 36 case m.Replace.Version != "": 37 return fmt.Sprintf("%s=>%s", m.Version, m.Replace.Version), m.Replace.Sum 38 case m.Replace.Path != "": 39 return fmt.Sprintf("%s=>%s", m.Version, m.Replace.Path), m.Replace.Sum 40 default: 41 return m.Version + "*", m.Sum + "*" 42 } 43 } 44 return m.Version, m.Sum 45 } 46 } 47 return "", "" 48 }