golang.org/x/tools/gopls@v0.15.3/internal/version/version.go (about)

     1  // Copyright 2024 The Go 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 version manages the gopls version.
     6  //
     7  // The VersionOverride variable may be used to set the gopls version at link
     8  // time.
     9  package version
    10  
    11  import "runtime/debug"
    12  
    13  var VersionOverride = ""
    14  
    15  // Version returns the gopls version.
    16  //
    17  // By default, this is read from runtime/debug.ReadBuildInfo, but may be
    18  // overridden by the [VersionOverride] variable.
    19  func Version() string {
    20  	if VersionOverride != "" {
    21  		return VersionOverride
    22  	}
    23  	if info, ok := debug.ReadBuildInfo(); ok {
    24  		if info.Main.Version != "" {
    25  			return info.Main.Version
    26  		}
    27  	}
    28  	return "(unknown)"
    29  }