This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/cmd/cmd.go

41 lines
742 B
Go
Raw Normal View History

2021-01-03 03:21:11 +00:00
package cmd
import (
2021-01-03 22:31:16 +00:00
"reichard.io/imagini/routes"
2021-01-06 19:36:09 +00:00
"reichard.io/imagini/internal/db"
2021-01-04 05:16:58 +00:00
2021-01-03 22:31:16 +00:00
"github.com/urfave/cli/v2"
"net/http"
"log"
2021-01-04 05:16:58 +00:00
"fmt"
2021-01-03 03:21:11 +00:00
)
var CmdServe = cli.Command{
2021-01-03 22:31:16 +00:00
Name: "serve",
Aliases: []string{"s"},
Usage: "Start Imagini web server.",
Action: serveWeb,
2021-01-03 03:21:11 +00:00
}
2021-01-04 05:16:58 +00:00
var CmdDBTest = cli.Command{
Name: "db",
Aliases: []string{"d"},
Usage: "test db.",
Action: testDatabase,
}
2021-01-03 03:21:11 +00:00
func serveWeb(ctx *cli.Context) error {
2021-01-03 22:31:16 +00:00
routes.RegisterRoutes()
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
2021-01-03 03:21:11 +00:00
return nil
}
2021-01-04 05:16:58 +00:00
func testDatabase(ctx *cli.Context) error {
resp := db.ItemsFromAlbum(1, 3)
fmt.Printf("%v", resp)
return nil
}