-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
41 lines (35 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"context"
"log"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/livefir/fir"
"github.com/livefir/fir/examples/fira/ent"
projects "github.com/livefir/fir/examples/fira/routes/projects"
_ "github.com/mattn/go-sqlite3"
)
func main() {
// db, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
db, err := ent.Open("sqlite3", "file:fira.db?cache=shared&_fk=1")
if err != nil {
log.Fatalf("failed opening connection to sqlite: %v", err)
}
defer db.Close()
ctx := context.Background()
// Run the auto migration tool.
if err := db.Schema.Create(ctx); err != nil {
log.Fatalf("failed creating schema resources: %v", err)
}
pathParamsOpt := fir.WithPathParamsFunc(
func(r *http.Request) fir.PathParams {
return fir.PathParams{
"id": chi.URLParam(r, "id"),
}
})
controller := fir.NewController("fira", fir.DevelopmentMode(true), pathParamsOpt)
r := chi.NewRouter()
r.Handle("/", controller.RouteFunc(projects.Index(db)))
r.Handle("/{id}/show", controller.RouteFunc(projects.Show(db)))
http.ListenAndServe(":9867", r)
}