prepping for release

This commit is contained in:
nate smith 2024-08-18 15:45:40 -05:00
parent 04c2142d78
commit 281e3ca53b
3 changed files with 14 additions and 11 deletions

View File

@ -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)
},
}

View File

@ -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

View File

@ -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))
}