-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (36 loc) · 913 Bytes
/
Copy pathmain.go
File metadata and controls
42 lines (36 loc) · 913 Bytes
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
package main
import (
"embed"
"html/template"
"io"
"github.com/jkaninda/logger"
"github.com/jkaninda/okapi"
"github.com/jkaninda/okapi-example/config"
"github.com/jkaninda/okapi-example/routes"
)
//go:embed views/*
var Views embed.FS
type Template struct {
templates *template.Template
}
func (t *Template) Render(w io.Writer, name string, data interface{}, c *okapi.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}
func NewTemplate() *Template {
tmpl := template.Must(template.ParseFS(Views, "views/*.html"))
return &Template{templates: tmpl}
}
func main() {
app := okapi.New()
conf := config.New()
if err := conf.Initialize(app); err != nil {
logger.Fatal("Failed to initialize config", "error", err)
}
app.WithRenderer(NewTemplate())
route := routes.New(app, conf)
route.RegisterRoutes()
// Start the server
if err := app.Start(); err != nil {
panic(err)
}
}