-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (55 loc) · 1.25 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"flag"
"fmt"
"log/slog"
"os"
"strings"
"github.com/onrik/supermock/pkg/app"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
)
func main() {
listen := flag.String("listen", "127.0.0.1:8000", "")
dbPath := flag.String("db", "sqlite://db.sqlite3", "")
templatesPath := flag.String("templates", "./templates", "")
debug := flag.Bool("debug", false, "")
flag.Parse()
logLevel := slog.LevelInfo
if debug != nil && *debug {
logLevel = slog.LevelDebug
}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: logLevel,
AddSource: true,
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
if a.Key != slog.SourceKey {
return a
}
source, ok := a.Value.Any().(*slog.Source)
if !ok {
return a
}
parts := strings.Split(source.File, "/")
var f string
if len(parts) >= 4 {
f = strings.Join(parts[len(parts)-2:], "/")
} else {
f = strings.Join(parts, "/")
}
return slog.Any(
a.Key,
fmt.Sprintf("%s:%d", f, source.Line),
)
},
})))
server, err := app.New(*listen, *dbPath, *templatesPath)
if err != nil {
slog.Error(err.Error())
return
}
if err := server.Run(); err != nil {
slog.Error(err.Error())
os.Exit(1)
}
}