/
main.go
39 lines (32 loc) · 810 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
package main
import (
"github.com/yarf-framework/yarf"
"net/http"
"time"
)
// Hello defines a simple resource
type Hello struct {
yarf.Resource // Extend the yarf.Resource by composition
}
// Get implements the GET handler
func (h *Hello) Get(c *yarf.Context) error {
c.Render("Hello world!")
return nil
}
// Entry point of the executable application
// This time we setup a custom Go http server and use YARF as a router.
func main() {
// Create a new empty YARF server
y := yarf.New()
// Add route/resource
y.Add("/", new(Hello))
// Configure custom http server and set the yarf object as Handler.
s := &http.Server{
Addr: ":8080",
Handler: y,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
s.ListenAndServe()
}