-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 841 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
40
41
42
43
44
45
46
47
48
49
package main
import (
"github.com/gin-gonic/gin"
"os"
"net/http"
)
const mainDir = `/home/daniel/workspace/go/src/web/.temp/`
func main() {
if err := os.Mkdir(mainDir, 0777); !os.IsExist(err) {
assert(err)
}
e := gin.New()
gp := e.Group("/api")
gp.Use(recovery)
fs := gp.Group("/filesystem")
fs.POST("", create)
fs.GET("/:id", get)
fs.PUT("/:id", update)
fs.DELETE("/:id", deleteHandler)
st := gp.Group("/stat")
st.GET("/count", totalSubDir)
st.GET("/alphanumerics", alphanumericStatics)
st.GET("/wordlen", wordLength)
st.GET("/size", size)
e.Run(":3412")
}
func recovery(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
println(err.(error).Error())
c.JSON(http.StatusInternalServerError, nil)
}
}()
c.Next()
}
func assert(err error) {
if err != nil {
println(err.Error())
}
}