-
Notifications
You must be signed in to change notification settings - Fork 0
/
gofh.go
79 lines (66 loc) · 1.6 KB
/
gofh.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
package gofh
import (
"github.com/teilomillet/gofh/internal/core"
"github.com/teilomillet/gofh/internal/server"
)
type Element = core.Element
type Context = core.Context
// App represents the main GoFH application
type App struct {
core *core.App
server *server.Server
}
// New creates a new GoFH application with the given options
func New(options ...Option) *App {
app := &App{
core: core.NewApp(),
server: server.NewServer(),
}
for _, option := range options {
option(app)
}
return app
}
// Text creates a text node Element
func Text(content string) Element {
return core.El("", content)
}
// Get adds a new GET route to the application
func (a *App) Get(path string) *RouteBuilder {
return &RouteBuilder{app: a, method: "GET", path: path}
}
// Post adds a new POST route to the application
func (a *App) Post(path string) *RouteBuilder {
return &RouteBuilder{app: a, method: "POST", path: path}
}
// RouteBuilder helps build routes with a fluent API
type RouteBuilder struct {
app *App
method string
path string
}
// Handle sets the handler for the route
func (rb *RouteBuilder) Handle(handler func(*Context) Element) {
rb.app.core.Route(rb.method, rb.path, handler)
}
// Serve starts the GoFH application server
func (a *App) Serve() error {
return a.server.Serve(a.core)
}
// Expose HTML element functions
var (
Div = core.Div
P = core.P
A = core.A
Span = core.Span
Input = core.Input
Form = core.Form
Button = core.Button
H1 = core.H1
H2 = core.H2
H3 = core.H3
Ul = core.Ul
Li = core.Li
El = core.El
// Add other elements as needed
)