2024-04-06 01:22:00 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-04-07 00:28:29 +07:00
|
|
|
"embed"
|
2024-04-08 21:50:52 +07:00
|
|
|
"errors"
|
|
|
|
"io/fs"
|
2024-04-06 01:22:00 +07:00
|
|
|
"os"
|
2024-04-12 01:32:06 +07:00
|
|
|
"os/signal"
|
2024-04-06 01:22:00 +07:00
|
|
|
|
2024-04-08 21:50:52 +07:00
|
|
|
"github.com/joho/godotenv"
|
2024-04-06 01:22:00 +07:00
|
|
|
"github.com/tigorlazuardi/redmage/cli"
|
2024-04-07 00:28:29 +07:00
|
|
|
"github.com/tigorlazuardi/redmage/db"
|
2024-04-06 01:22:00 +07:00
|
|
|
)
|
|
|
|
|
2024-04-07 23:41:00 +07:00
|
|
|
//go:embed db/migrations/*.sql
|
|
|
|
var Migrations embed.FS
|
2024-04-07 00:28:29 +07:00
|
|
|
|
2024-04-08 21:50:52 +07:00
|
|
|
//go:embed public/*
|
|
|
|
var PublicFS embed.FS
|
|
|
|
|
2024-04-06 01:22:00 +07:00
|
|
|
func main() {
|
2024-04-08 21:50:52 +07:00
|
|
|
_ = godotenv.Load()
|
2024-04-07 23:41:00 +07:00
|
|
|
db.Migrations = Migrations
|
2024-04-08 21:50:52 +07:00
|
|
|
var err error
|
2024-04-09 14:30:54 +07:00
|
|
|
cli.PublicDir, err = fs.Sub(PublicFS, "public")
|
2024-04-08 21:50:52 +07:00
|
|
|
if err != nil {
|
|
|
|
panic(errors.New("failed to create sub filesystem"))
|
|
|
|
}
|
2024-04-12 01:32:06 +07:00
|
|
|
|
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
|
|
|
|
defer stop()
|
|
|
|
|
|
|
|
if err := cli.RootCmd.ExecuteContext(ctx); err != nil {
|
2024-04-06 01:22:00 +07:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|