From 281e3ca53bfdcb6d0fb6b20acd5c14e0162fd764 Mon Sep 17 00:00:00 2001 From: nate smith Date: Sun, 18 Aug 2024 15:45:40 -0500 Subject: [PATCH] prepping for release --- cmd/serve.go | 9 ++++++++- db/db.go | 8 -------- web/web.go | 8 ++++++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/serve.go b/cmd/serve.go index 4006d68..1d40382 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -6,12 +6,19 @@ import ( ) func init() { + cutupCmd.Flags().IntP("port", "p", 8080, "port to listen on") rootCmd.AddCommand(serveCmd) } var serveCmd = &cobra.Command{ Use: "serve", RunE: func(cmd *cobra.Command, args []string) error { - return web.Serve() + port, _ := cmd.Flags().GetInt("port") + + opts := web.ServeOpts{ + Port: port, + } + + return web.Serve(opts) }, } diff --git a/db/db.go b/db/db.go index 5aa3853..6969488 100644 --- a/db/db.go +++ b/db/db.go @@ -9,12 +9,6 @@ import ( "github.com/jackc/pgx/v5/pgxpool" ) -const ( - // TODO unused; i think i failed to make this work. should i just rely on the env - // vars like i've been doing? - dburl = "postgresql://vilmibm/postgres?host=/home/vilmibm/src/trunkless/pgdata/sockets" -) - func StrToID(s string) string { return fmt.Sprintf("%x", sha1.Sum([]byte(s)))[0:6] } @@ -36,5 +30,3 @@ func Pool() (*pgxpool.Pool, error) { return pool, nil } - -// TODO func for getting ID ranges for each corpus in phrases diff --git a/web/web.go b/web/web.go index 4137c50..805dec1 100644 --- a/web/web.go +++ b/web/web.go @@ -31,7 +31,11 @@ type corpus struct { MaxID *big.Int } -func Serve() error { +type ServeOpts struct { + Port int +} + +func Serve(opts ServeOpts) error { r := gin.Default() r.SetFuncMap(template.FuncMap{ "upper": strings.ToUpper, @@ -187,5 +191,5 @@ func Serve() error { c.JSON(http.StatusOK, p) }) - return r.Run() // 8080 + return r.Run(fmt.Sprintf(":%d", opts.Port)) }