diff --git a/config/banner.go b/config/banner.go new file mode 100644 index 0000000..9082563 --- /dev/null +++ b/config/banner.go @@ -0,0 +1,77 @@ +package config + +import ( + "fmt" + "math" + "strings" + "unicode/utf8" +) + +func PrintStartupBanner() { + fmt.Println(getBanner() + "\n") + fmt.Printf("Basic Auth mode: %v\n", GetBasicAuthMode()) + fmt.Printf("HTTP mode : %v\n", GetHttpMode()) + fmt.Printf("Readonly mode : %v\n", GetReadonlyMode()) + fmt.Printf("Sinkhole mode : %v\n", GetSinkholeMode()) + fmt.Printf("Path : %s\n", GetPathDataFolder()) + + if GetBasicAuthMode() { + fmt.Printf("Username : %s\n", GetBasicAuthUsername()) + fmt.Printf("Password : %s\n", GetBasicAuthPassword()) + } + + if GetHttpMode() { + fmt.Printf("Listening on : http://0.0.0.0:%d\n", GetPortToListenOn()) + } else { + if pathTLSCertFile == "" || pathTLSKeyFile == "" { + fmt.Printf("TLS cert : self-signed\n") + fmt.Printf("TLS key : self-signed\n") + } else { + fmt.Printf("TLS cert : %s\n", pathTLSCertFile) + fmt.Printf("TLS key : %s\n", pathTLSKeyFile) + } + + fmt.Printf("Listening on : https://0.0.0.0:%d\n", GetPortToListenOn()) + } + + fmt.Println("") +} + +func centerTextWithWhitespaces(text string, maxWidth int) string { + textLength := utf8.RuneCountInString(text) + if textLength >= maxWidth { + return text + } + + totalPadding := maxWidth - textLength + leftPadding := int(math.Ceil((float64(totalPadding) / 2.0))) + rightPadding := totalPadding - leftPadding + + return strings.Repeat(" ", leftPadding) + text + strings.Repeat(" ", rightPadding) +} + +func getBanner() string { + version := centerTextWithWhitespaces("v"+VersionString, 38) + + // if runtime.GOOS != "windows" { + // return strings.Join( + // []string{ + // "+--------------------------------------+", + // "│ Ablage │", + // fmt.Sprintf("│%s│", version), + // "+--------------------------------------+", + // }, + // "\n", + // ) + // } + + return strings.Join( + []string{ + "┌──────────────────────────────────────┐", + "│ Ablage │", + fmt.Sprintf("│%s│", version), + "└──────────────────────────────────────┘", + }, + "\n", + ) +} diff --git a/config/config.go b/config/config.go index 2aa5b27..0194333 100644 --- a/config/config.go +++ b/config/config.go @@ -33,36 +33,3 @@ func Init() { os.Exit(1) } } - -func PrintStartupBanner() { - fmt.Println("****************************************") - fmt.Println("* Ablage *") - fmt.Println("****************************************") - fmt.Printf("Version : %s\n", VersionString) - fmt.Printf("Basic Auth mode: %v\n", GetBasicAuthMode()) - fmt.Printf("HTTP mode : %v\n", GetHttpMode()) - fmt.Printf("Readonly mode : %v\n", GetReadonlyMode()) - fmt.Printf("Sinkhole mode : %v\n", GetSinkholeMode()) - fmt.Printf("Path : %s\n", GetPathDataFolder()) - - if GetBasicAuthMode() { - fmt.Printf("Username : %s\n", GetBasicAuthUsername()) - fmt.Printf("Password : %s\n", GetBasicAuthPassword()) - } - - if GetHttpMode() { - fmt.Printf("Listening on : http://0.0.0.0:%d\n", GetPortToListenOn()) - } else { - if pathTLSCertFile == "" || pathTLSKeyFile == "" { - fmt.Printf("TLS cert : self-signed\n") - fmt.Printf("TLS key : self-signed\n") - } else { - fmt.Printf("TLS cert : %s\n", pathTLSCertFile) - fmt.Printf("TLS key : %s\n", pathTLSKeyFile) - } - - fmt.Printf("Listening on : https://0.0.0.0:%d\n", GetPortToListenOn()) - } - - fmt.Println("") -}