cmd: print current version name on cmd and Via header

This commit is contained in:
WeebDataHoarder
2025-04-23 20:44:51 +02:00
parent 57755112ea
commit cb02fb20e9
3 changed files with 19 additions and 7 deletions

View File

@@ -76,14 +76,19 @@ func setupListener(network, address, socketMode string, proxy bool) (net.Listene
return listener, formattedAddress
}
var internalPackageName = func() string {
var internalCmdName = "go-away"
var internalMainName = "go-away"
var internalMainVersion = "dev"
func init() {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return "go-away"
return
}
return buildInfo.Path
}()
internalCmdName = buildInfo.Path
internalMainName = buildInfo.Main.Path
internalMainVersion = buildInfo.Main.Version
}
type MultiVar []string
@@ -141,7 +146,7 @@ func main() {
challengeTemplate := flag.String("challenge-template", "anubis", "name or path of the challenge template to use (anubis, forgejo)")
challengeTemplateTheme := flag.String("challenge-template-theme", "", "name of the challenge template theme to use (forgejo => [forgejo-auto, forgejo-dark, forgejo-light, gitea...])")
packageName := flag.String("package-path", internalPackageName, "package name to expose in .well-known url path")
packageName := flag.String("package-path", internalCmdName, "package name to expose in .well-known url path")
jwtPrivateKeySeed := flag.String("jwt-private-key-seed", "", "Seed for the jwt private key, or on JWT_PRIVATE_KEY_SEED env. One be generated by passing \"generate\" as a value, follows RFC 8032 private key definition. Defaults to random")
@@ -169,6 +174,8 @@ func main() {
slog.SetDefault(slog.New(h))
}
slog.Info("go-away", "package", internalMainName, "version", internalMainVersion, "cmd", internalCmdName)
var seed []byte
var kValue string
@@ -281,6 +288,8 @@ func main() {
Cache: cache,
Backends: createdBackends,
Debug: *debugMode,
MainName: internalMainName,
MainVersion: internalMainVersion,
PackageName: *packageName,
ChallengeTemplate: *challengeTemplate,
ChallengeTemplateTheme: *challengeTemplateTheme,

View File

@@ -179,8 +179,9 @@ func (state *State) ServeHTTP(w http.ResponseWriter, r *http.Request) {
data.EvaluateChallenges(w, r)
// TODO: make this configurable!
w.Header().Add("Via", fmt.Sprintf("%s %s", r.Proto, "go-away"))
if state.Settings().MainName != "" {
w.Header().Add("Via", fmt.Sprintf("%s %s@%s", r.Proto, state.Settings().MainName, state.Settings().MainVersion))
}
state.Mux.ServeHTTP(w, r)
}

View File

@@ -10,6 +10,8 @@ type Settings struct {
Backends map[string]http.Handler
PrivateKeySeed []byte
Debug bool
MainName string
MainVersion string
PackageName string
ChallengeTemplate string
ChallengeTemplateTheme string