mirror of https://github.com/libp2p/go-libp2p.git
Marten Seemann
3 years ago
3 changed files with 66 additions and 14 deletions
@ -0,0 +1,23 @@ |
|||
//go:build !go1.18
|
|||
// +build !go1.18
|
|||
|
|||
package identify |
|||
|
|||
import ( |
|||
"fmt" |
|||
"runtime/debug" |
|||
) |
|||
|
|||
func init() { |
|||
bi, ok := debug.ReadBuildInfo() |
|||
// ok will only be true if this is built as a dependency of another module
|
|||
if !ok { |
|||
return |
|||
} |
|||
version := bi.Main.Version |
|||
if version == "(devel)" { |
|||
defaultUserAgent = bi.Main.Path |
|||
} else { |
|||
defaultUserAgent = fmt.Sprintf("%s@%s", bi.Main.Path, bi.Main.Version) |
|||
} |
|||
} |
@ -0,0 +1,43 @@ |
|||
//go:build go1.18
|
|||
// +build go1.18
|
|||
|
|||
package identify |
|||
|
|||
import ( |
|||
"fmt" |
|||
"runtime/debug" |
|||
) |
|||
|
|||
func init() { |
|||
bi, ok := debug.ReadBuildInfo() |
|||
if !ok { |
|||
return |
|||
} |
|||
version := bi.Main.Version |
|||
// version will only be non-empty if built as a dependency of another module
|
|||
if version == "" { |
|||
return |
|||
} |
|||
|
|||
if version != "(devel)" { |
|||
defaultUserAgent = fmt.Sprintf("%s@%s", bi.Main.Path, bi.Main.Version) |
|||
return |
|||
} |
|||
|
|||
var revision string |
|||
var dirty bool |
|||
for _, bs := range bi.Settings { |
|||
switch bs.Key { |
|||
case "vcs.revision": |
|||
revision = bs.Value |
|||
case "vcs.modified": |
|||
if bs.Value == "true" { |
|||
dirty = true |
|||
} |
|||
} |
|||
} |
|||
defaultUserAgent = fmt.Sprintf("%s@%s", bi.Main.Path, revision) |
|||
if dirty { |
|||
defaultUserAgent += " (dirty)" |
|||
} |
|||
} |
Loading…
Reference in new issue