forked from francescomalatesta/httpstatus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (34 loc) · 1.22 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
package main
import (
"fmt"
"strconv"
"github.com/labstack/echo"
"httpstatus/statuscodes"
)
func handleStatusCodeRequest(c echo.Context) error {
allowedCodes := statuscodes.GetAllowedCodes()
statusCode, _ := strconv.Atoi(c.Param("statusCode"))
if allowedCodes.IsInList(statusCode) {
return c.String(statusCode, "")
}
return c.String(500, fmt.Sprintf("Error: status code %s is not available.", c.Param("statusCode")))
}
func main() {
e := echo.New()
e.File("/", "public/index.html")
e.GET("/:statusCode", handleStatusCodeRequest)
e.GET("/:statusCode/*", handleStatusCodeRequest)
e.POST("/:statusCode", handleStatusCodeRequest)
e.POST("/:statusCode/*", handleStatusCodeRequest)
e.PUT("/:statusCode", handleStatusCodeRequest)
e.PUT("/:statusCode/*", handleStatusCodeRequest)
e.PATCH("/:statusCode", handleStatusCodeRequest)
e.PATCH("/:statusCode/*", handleStatusCodeRequest)
e.DELETE("/:statusCode", handleStatusCodeRequest)
e.DELETE("/:statusCode/*", handleStatusCodeRequest)
e.OPTIONS("/:statusCode", handleStatusCodeRequest)
e.OPTIONS("/:statusCode/*", handleStatusCodeRequest)
e.HEAD("/:statusCode", handleStatusCodeRequest)
e.HEAD("/:statusCode/*", handleStatusCodeRequest)
e.Logger.Fatal(e.Start(":8080"))
}