From b76502c034d197000eb24cf7e62e4f9330701327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Fri, 3 Jul 2026 09:09:55 +0200 Subject: [PATCH] Version printing from command line arguments --- main.go | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index ff935ad..aeba690 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,7 @@ var ( FlagConfig string FlagCreateUser string FlagChangePassword string + FlagVersion bool Webengine HTMLTemplate.Engine config Config Log *slog.Logger @@ -66,6 +67,7 @@ func init() { // {{{ flag.BoolVar(&FlagLoremIpsum, "lorem-ipsum", false, "Replace all G- nodes with lorem ipsum paragraphs") flag.StringVar(&FlagCreateUser, "create-user", "", "Username for creating a new user") flag.StringVar(&FlagChangePassword, "change-password", "", "Change the password for the given username") + flag.BoolVar(&FlagVersion, "version", false, "Print version and exit") flag.Parse() RxpBearerToken = regexp.MustCompile("(?i)^\\s*Bearer\\s+(.*?)\\s*$") @@ -76,7 +78,14 @@ func initLog() { // {{{ Log = slog.New(slog.NewJSONHandler(os.Stdout, &opts)) } // }}} func main() { // {{{ + if FlagVersion { + fmt.Println(VERSION) + return + } + initLog() + Log.Info("application", "version", VERSION) + err := readConfig(FlagConfig) if err != nil { Log.Error("config", "error", err) @@ -443,7 +452,7 @@ func actionSyncFileUpload(w http.ResponseWriter, r *http.Request) { // {{{ Log.Info("file_upload", "status", "done", "user", session.UserID, "uuid", uuid, "total", totalBytes) id := fileUUIDCache[uuid] delete(fileUUIDCache, uuid) - _, err = db.Exec(`UPDATE public.file SET upload_complete = true WHERE id = $1`, id) + _, err = db.Exec(`UPDATE public.file SET upload_complete = true WHERE id = $1`, id) default: id := fileUUIDCache[uuid] @@ -502,7 +511,7 @@ func actionUserSetPreferences(w http.ResponseWriter, r *http.Request) { // {{{ }) } // }}} -func actionFileCount(w http.ResponseWriter, r *http.Request) {// {{{ +func actionFileCount(w http.ResponseWriter, r *http.Request) { // {{{ session := getUserSession(r) count, err := FileCountForUser(session.UserID) if err != nil { @@ -512,11 +521,11 @@ func actionFileCount(w http.ResponseWriter, r *http.Request) {// {{{ } responseData(w, map[string]any{ - "OK": true, + "OK": true, "Count": count, }) -}// }}} -func actionFileServerUUIDs(w http.ResponseWriter, r *http.Request) {// {{{ +} // }}} +func actionFileServerUUIDs(w http.ResponseWriter, r *http.Request) { // {{{ session := getUserSession(r) offset, _ := strconv.Atoi(r.PathValue("offset")) uuids, more, err := FileServerUUIDsForUser(session.UserID, offset) @@ -527,12 +536,12 @@ func actionFileServerUUIDs(w http.ResponseWriter, r *http.Request) {// {{{ } responseData(w, map[string]any{ - "OK": true, - "UUIDs": uuids, + "OK": true, + "UUIDs": uuids, "MoreRowsExist": more, }) -}// }}} -func actionFile(w http.ResponseWriter, r *http.Request) {// {{{ +} // }}} +func actionFile(w http.ResponseWriter, r *http.Request) { // {{{ uuid := r.PathValue("uuid") session := getUserSession(r) f, md, err := FileForUser(session.UserID, uuid) @@ -543,8 +552,8 @@ func actionFile(w http.ResponseWriter, r *http.Request) {// {{{ } http.ServeContent(w, r, md.Name, md.Modified, f) -}// }}} -func actionFileMetadata(w http.ResponseWriter, r *http.Request) {// {{{ +} // }}} +func actionFileMetadata(w http.ResponseWriter, r *http.Request) { // {{{ uuid := r.PathValue("uuid") session := getUserSession(r) md, err := FileMetadata(session.UserID, uuid) @@ -556,10 +565,10 @@ func actionFileMetadata(w http.ResponseWriter, r *http.Request) {// {{{ } responseData(w, map[string]any{ - "OK": true, + "OK": true, "Metadata": md, }) -}// }}} +} // }}} func createNewUser(username string) { // {{{ reader := bufio.NewReader(os.Stdin)