From 96a76c1ffd27ae3f0262e44d62650699bcf9d0f5 Mon Sep 17 00:00:00 2001 From: Dominic Ricottone Date: Sun, 7 Apr 2024 14:20:04 -0500 Subject: [PATCH] Cleanup remaining TODOs --- Makefile | 1 + config.go | 42 +++++++++++++++++++++++++++++------------- main.go | 10 +++++++++- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 7b8708a..e16f16e 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ GO_SRC!=find * -type f -name '*.go' GO_LDFLAGS:= GO_LDFLAGS+=-X main.CLIENTID=$(file < clientid.txt) GO_LDFLAGS+=-X main.CLIENTSECRET=$(file < clientsecret.txt) +# TODO: GO_LDFLAGS+=-X main.VERSION=0.0.1 nspotify: go.mod $(GO_SRC) go build -ldflags "$(GO_LDFLAGS)" . diff --git a/config.go b/config.go index f342227..cccf056 100644 --- a/config.go +++ b/config.go @@ -7,41 +7,54 @@ import ( log "github.com/sirupsen/logrus" ) -// Number of tracks to fetch into a buffer. -const fetchingBuffer = 100 +// Compile-time configurations. +const ( + // Number of tracks to fetch into a buffer. + fetchingBuffer = 100 -// Number of seconds to wait before rechecking the lazy fetcher. -const fetchingTimeout = 3 + // Number of seconds to wait before rechecking the lazy fetcher. + fetchingTimeout = 3 -// Number of tracks to eagerly load. -const loadEager = 50 + // Number of tracks to eagerly load. + loadEager = 50 -// Number of tracks to lazily load ahead of the cursor. -const loadLookahead = 50 + // Number of tracks to lazily load ahead of the cursor. + loadLookahead = 50 -// Number of seconds to wait before rechecking how many trackers are loaded -// ahead of the cursor. -const loadTimeout = 3 + // Number of seconds to wait before rechecking how many trackers are loaded + // ahead of the cursor. + loadTimeout = 3 +) + +// TODO: Compile-time variables. +// These should be set by the linker. +// e.g. `go build -ldflags="-X 'main.VERSION=0.1.2'"` +// var ( +// VERSION = "" +// ) -// Command line options. +// Run-time configurations. var ( verbose = flag.Bool("verbose", false, "Show debugging messages (same as '-log-level=trace')") quiet = flag.Bool("quiet", false, "Suppress messages (same as '-log-level=panic')") log_level = flag.String("log-level", "", "Set logging level to `[trace|debug|info|warning|error|fatal|panic]`") - //TODO: log_file = flag.String("log-file", "", "Log to `file`") + // TODO: log_file = flag.String("log-file", "", "Log to `file`") color = flag.Bool("color", true, "Display in color") port = flag.Int("port", 8080, "Spotify authenticator port") cache = flag.String("cache", "", "Cache `directory`") no_cache = flag.Bool("no-cache", false, "Do not use cached authentication, do not cache authentication") device = flag.String("device", "", "Spotify device `ID`") list_devices = flag.Bool("list-devices", false, "List available Spotify devices and exit") + // TODO: version = flag.Bool("version", false, "List version and exit") ) +// Create a pointer to a value, especially a string. // Credit to `https://stackoverflow.com/a/30716481`: func Pointer[T any](v T) *T { return &v } +// Create a context with configurations applied. func ConfiguredContext() context.Context { ctx := context.Background() @@ -100,6 +113,9 @@ func ConfiguredContext() context.Context { } ctx = context.WithValue(ctx, "device", *device) + // TODO: Signal `-version` by setting the version variable. + // ctx = context.WithValue(ctx, "version", VERSION) + return ctx } diff --git a/main.go b/main.go index b2dd92e..88b5fc4 100644 --- a/main.go +++ b/main.go @@ -10,9 +10,17 @@ func main() { ctx := ConfiguredContext() ctx, cancel := context.WithCancel(ctx) + // TODO: Display version mode. + // version, ok := ctx.Value("version").(string) + // if ok && (version != "") { + // fmt.Println("nspotify %s", version) + // cancel() + // return + // } + // Authenticate with Spotify. cli := Authenticate(ctx) - //TODO: incorporate rate limiting? "set the AutoRetry field on the Client struct to true" + // TODO: incorporate rate limiting? "set the AutoRetry field on the Client struct to true" // List devices mode. sdev, ok := ctx.Value("device").(string) -- 2.45.2