Skip to content

Commit

Permalink
Add version information; update release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
v1k45 committed Jun 30, 2024
1 parent 246bfb3 commit 9e1add5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ jobs:
goarch: ${{ matrix.goarch }}
compress_assets: false
asset_name: pastepass-${{ matrix.goos }}-${{ matrix.goarch }}
ldflags: -X "github.com/v1k45/pastepass/config.Version=${{ github.ref_name }}"
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ var (
AppName = "PastePass"
DBPath = "pastepass.boltdb"
ResetDB = false
Version = "0.00-dev"
)
27 changes: 19 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ package main

import (
"flag"
"github.com/v1k45/pastepass/config"
"fmt"
"log"
"log/slog"
"net/http"
"time"

"github.com/v1k45/pastepass/config"
"github.com/v1k45/pastepass/db"
"github.com/v1k45/pastepass/web"
)

func main() {
flag.StringVar(&config.ServerAddr, "server-addr", config.ServerAddr, "The server address to listen on")
flag.StringVar(&config.AppName, "app-name", config.AppName, "The name of the application (e.g. ACME PastePass)")
flag.StringVar(&config.DBPath, "db-path", config.DBPath, "The path to the database file")
flag.BoolVar(&config.ResetDB, "reset-db", config.ResetDB, "Reset the database on startup")
flag.Parse()
parseFlags()

// Open the database
boltdb, err := db.NewDB(config.DBPath, config.ResetDB)
Expand All @@ -26,9 +23,23 @@ func main() {
}
go boltdb.DeleteExpiredPeriodically(time.Minute * 5)

slog.Info("starting_server", "server_addr", config.ServerAddr, "app_name", config.AppName, "db_name", config.DBPath)

// Start the web server
slog.Info("starting_server", "server_addr", config.ServerAddr, "app_name", config.AppName, "db_name", config.DBPath)
handler := web.NewHandler(boltdb)
http.ListenAndServe(config.ServerAddr, handler.Router())
}

func parseFlags() {
flag.Usage = func() {
fmt.Printf("pastepass - %s\n\n", config.Version)
fmt.Fprintf(flag.CommandLine.Output(), "Usage:\n")
flag.PrintDefaults()
}

flag.StringVar(&config.ServerAddr, "server-addr", config.ServerAddr, "The server address to listen on")
flag.StringVar(&config.AppName, "app-name", config.AppName, "The name of the application (e.g. ACME PastePass)")
flag.StringVar(&config.DBPath, "db-path", config.DBPath, "The path to the database file")
flag.BoolVar(&config.ResetDB, "reset-db", config.ResetDB, "Reset the database on startup")

flag.Parse()
}

0 comments on commit 9e1add5

Please sign in to comment.