-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (38 loc) · 847 Bytes
/
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
42
43
44
45
package main
import (
"database/sql"
"github.com/caleb-hoyne/slogctx"
"github.com/caleb-hoyne/sqllite-test/handler"
"github.com/caleb-hoyne/sqllite-test/repository"
_ "github.com/mattn/go-sqlite3"
"log/slog"
"net/http"
"os"
)
const dbPath = "test.db"
func main() {
pool, err := sql.Open("sqlite3", dbPath)
if err != nil {
panic(err)
}
defer pool.Close()
slog.SetDefault(slog.New(&slogctx.Handler{
Handler: slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{}),
}))
_, err = pool.Exec("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT)")
if err != nil {
panic(err)
}
nameHandler := &handler.RequestHandler{
R: &db.Repository{
DB: pool,
},
}
mux := http.NewServeMux()
mux.Handle("/name/", nameHandler)
s := http.Server{
Addr: ":8080",
Handler: mux,
}
panic(s.ListenAndServe())
}