-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.go
72 lines (66 loc) · 1.47 KB
/
server.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
package main
import (
"fmt"
"github.com/firmeve/firmeve"
"github.com/firmeve/firmeve/binding"
"github.com/firmeve/firmeve/kernel"
"github.com/firmeve/firmeve/kernel/contract"
"github.com/firmeve/firmeve/render"
)
type App struct {
kernel.BaseProvider
}
func (a *App) Name() string {
return `app`
}
func (a *App) Register() {
}
func (a *App) Boot() {
router := a.Firmeve.Get(`http.router`).(contract.HttpRouter)
web := router.Group("")
{
web.GET("/", func(c contract.Context) {
c.RenderWith(200, render.Html, render.Template{
Name: "index",
Append: nil,
})
c.Next()
})
web.POST("/uploads", func(c contract.Context) {
fmt.Println(c.Protocol().(contract.HttpProtocol).ContentType())
type FileStruct struct {
Text string `form:"text"`
Files binding.MultipartFiles
}
v := new(FileStruct)
c.Bind(v)
files, err := v.Files.Save(`file`, &contract.UploadOption{
Path: "./files",
Grading: true,
Rename: true,
})
if err != nil {
c.Error(400, err)
return
}
fmt.Printf("%#v\n", files)
c.RenderWith(200, render.Plain, files[0])
c.Next()
})
web.POST("/stream", func(c contract.Context) {
//bytes.NewBuffer(make([]byte, 0))
msg, _ := c.Protocol().Message()
fmt.Printf("%s", msg)
//var buff = new(bytes.Buffer)
//c.Bind(buff)
c.Next()
})
}
}
func main() {
firmeve.RunDefault(firmeve.WithConfigPath("../config.yaml"), firmeve.WithProviders(
[]contract.Provider{
new(App),
},
))
}