Automatically fetch own package name for running binary

This commit is contained in:
WeebDataHoarder
2025-04-06 03:15:50 +02:00
parent 411f028f56
commit 7a20d0c738

View File

@@ -17,6 +17,7 @@ import (
"net"
"net/http"
"os"
"runtime/debug"
"strconv"
"strings"
)
@@ -55,6 +56,15 @@ func setupListener(network, address, socketMode string) (net.Listener, string) {
return listener, formattedAddress
}
var internalPackageName = func() string {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return "go-away"
}
return buildInfo.Path
}()
type MultiVar []string
func (v *MultiVar) String() string {
@@ -78,7 +88,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-dark, forgejo-light, gitea...])")
packageName := flag.String("package-path", "git.gammaspectra.live/git/go-away/cmd/go-away", "package name to expose in .well-known url path")
packageName := flag.String("package-path", internalPackageName, "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")