-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.go
62 lines (47 loc) · 1.33 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
package main
import (
"gis/app"
"gis/app/controllers"
"github.com/valyala/fasthttp"
"github.com/buaazp/fasthttprouter"
)
// gis (go image server)
var (
imageController = controllers.NewImageController()
)
func main() {
go func() {
defer func() {
e := recover()
if e != nil {
app.Log.Errorf("gis upload server crash, %v", e)
}
}()
uploadServer()
}()
downloadServer()
}
// 上传 server
func uploadServer() {
uploadServer := app.Conf.GetString("listen.upload")
router := fasthttprouter.New()
router.POST("/image/upload", imageController.Upload)
router.OPTIONS("/image/upload", imageController.CrossDomain)
app.Log.Infof("upload server start listen: %s", uploadServer)
err := fasthttp.ListenAndServe(uploadServer, router.Handler)
if err != nil {
app.Log.Errorf("listen upload server %s error: %s", uploadServer, err.Error())
}
}
// 下载 server
func downloadServer() {
downloadServer := app.Conf.GetString("listen.download")
router := fasthttprouter.New()
router.GET("/image/:name", imageController.Download)
router.OPTIONS("/image/:name", imageController.CrossDomain)
app.Log.Infof("download server start listen: %s", downloadServer)
err := fasthttp.ListenAndServe(downloadServer, router.Handler)
if err != nil {
app.Log.Errorf("listen download server %s error: %s", downloadServer, err.Error())
}
}