...

Source file src/gonum.org/v1/plot/version.go

Documentation: gonum.org/v1/plot

     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  //go:build go1.12
     6  // +build go1.12
     7  
     8  package plot
     9  
    10  import (
    11  	"fmt"
    12  	"runtime/debug"
    13  )
    14  
    15  const root = "gonum.org/v1/plot"
    16  
    17  // Version returns the version of Gonum/plot and its checksum. The returned
    18  // values are only valid in binaries built with module support.
    19  //
    20  // If a replace directive exists in the Gonum/plot go.mod, the replace will
    21  // be reported in the version in the following format:
    22  //
    23  //	"version=>[replace-path] [replace-version]"
    24  //
    25  // and the replace sum will be returned in place of the original sum.
    26  //
    27  // The exact version format returned by Version may change in future.
    28  func Version() (version, sum string) {
    29  	b, ok := debug.ReadBuildInfo()
    30  	if !ok {
    31  		return "", ""
    32  	}
    33  	for _, m := range b.Deps {
    34  		if m.Path == root {
    35  			if m.Replace != nil {
    36  				switch {
    37  				case m.Replace.Version != "" && m.Replace.Path != "":
    38  					return fmt.Sprintf("%s=>%s %s", m.Version, m.Replace.Path, m.Replace.Version), m.Replace.Sum
    39  				case m.Replace.Version != "":
    40  					return fmt.Sprintf("%s=>%s", m.Version, m.Replace.Version), m.Replace.Sum
    41  				case m.Replace.Path != "":
    42  					return fmt.Sprintf("%s=>%s", m.Version, m.Replace.Path), m.Replace.Sum
    43  				default:
    44  					return m.Version + "*", m.Sum + "*"
    45  				}
    46  			}
    47  			return m.Version, m.Sum
    48  		}
    49  	}
    50  	return "", ""
    51  }
    52  

View as plain text