...

Source file src/github.com/Microsoft/hcsshim/osversion/osversion_windows.go

Documentation: github.com/Microsoft/hcsshim/osversion

     1  package osversion
     2  
     3  import (
     4  	"fmt"
     5  	"sync"
     6  
     7  	"golang.org/x/sys/windows"
     8  )
     9  
    10  // OSVersion is a wrapper for Windows version information
    11  // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724439(v=vs.85).aspx
    12  type OSVersion struct {
    13  	Version      uint32
    14  	MajorVersion uint8
    15  	MinorVersion uint8
    16  	Build        uint16
    17  }
    18  
    19  var (
    20  	osv  OSVersion
    21  	once sync.Once
    22  )
    23  
    24  // Get gets the operating system version on Windows.
    25  // The calling application must be manifested to get the correct version information.
    26  func Get() OSVersion {
    27  	once.Do(func() {
    28  		var err error
    29  		osv = OSVersion{}
    30  		osv.Version, err = windows.GetVersion()
    31  		if err != nil {
    32  			// GetVersion never fails.
    33  			panic(err)
    34  		}
    35  		osv.MajorVersion = uint8(osv.Version & 0xFF)
    36  		osv.MinorVersion = uint8(osv.Version >> 8 & 0xFF)
    37  		osv.Build = uint16(osv.Version >> 16)
    38  	})
    39  	return osv
    40  }
    41  
    42  // Build gets the build-number on Windows
    43  // The calling application must be manifested to get the correct version information.
    44  func Build() uint16 {
    45  	return Get().Build
    46  }
    47  
    48  // String returns the OSVersion formatted as a string. It implements the
    49  // [fmt.Stringer] interface.
    50  func (osv OSVersion) String() string {
    51  	return fmt.Sprintf("%d.%d.%d", osv.MajorVersion, osv.MinorVersion, osv.Build)
    52  }
    53  
    54  // ToString returns the OSVersion formatted as a string.
    55  //
    56  // Deprecated: use [OSVersion.String].
    57  func (osv OSVersion) ToString() string {
    58  	return osv.String()
    59  }
    60  

View as plain text