Skip to content

Commit

Permalink
version string
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Aug 31, 2023
1 parent 849da02 commit 7818dc9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions libgobuster/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package libgobuster
import (
"fmt"
"runtime/debug"
"strconv"
)

const (
Expand All @@ -11,16 +12,35 @@ const (
)

func GetVersion() string {
version := VERSION
modified := false
revision := ""
time := ""
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
version = fmt.Sprintf("%s Revision %s", version, setting.Value)
revision = setting.Value
}
if setting.Key == "vcs.time" {
version = fmt.Sprintf("%s from %s", version, setting.Value)
time = setting.Value
}
if setting.Key == "vcs.modified" {
if mod, err := strconv.ParseBool(setting.Value); err == nil {
modified = mod
}
}
}
}
version := VERSION
if revision != "" {
version = fmt.Sprintf("%s Revision %s", version, revision)
}

if modified {
version = fmt.Sprintf("%s [DIRTY]", version)
}
if time != "" {
version = fmt.Sprintf("%s from %s", version, time)
}

return version
}

0 comments on commit 7818dc9

Please sign in to comment.