-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
80 lines (67 loc) · 1.57 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"net/http"
"os"
"time"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func init() {
// Initialize default global logger.
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{
Out: os.Stderr,
TimeFormat: time.DateTime,
})
// Debug mode by default.
// todo(zvezdochka): explicit debug flag when start.
zerolog.SetGlobalLevel(zerolog.DebugLevel)
// Initialize other services.
initialization := Maybe{
compileTemplates,
func() error {
return assignSqlite("dev.db")
},
migrate,
func() error {
initCaptchas()
return nil
},
}
err := initialization.Eval()
if err != nil {
log.Fatal().Msg(err.Error())
}
}
func main() {
e := echo.New()
e.Use(
LoggingMiddleware,
middleware.Recover(),
middleware.CORS(),
)
// Serve static files.
e.Static("/static", "static")
e.Static("/src", FileDirectory)
e.Static("/thumb", ThumbDirectory)
e.GET("/favicon.ico", func(c echo.Context) error {
return c.Redirect(http.StatusPermanentRedirect, "/static/favicon.ico")
})
// Serve pages.
e.GET("/", serveMain)
e.GET("/:board", serveBoard)
e.GET("/:board/:id", serveThread)
// Rest api.
api := e.Group("/api")
api.GET("/get_boards", getBoards)
api.POST("/post", createPost)
// Captcha.
api.GET("/captcha/new", newCaptcha)
api.GET("/captcha/get", getCaptcha)
// Admin routes.
api.POST("/create_board", createBoard)
// api.GET("/ban_yourself", bantest)
log.Info().Msg(e.Start(":3000").Error())
}