/
server.go
51 lines (39 loc) · 1.03 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
package main
import (
"fmt"
"net/http"
//"runtime"
"log"
"time"
"github.com/facebookgo/grace/gracehttp"
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
)
func okJSON(c *echo.Context, value interface{}) error {
return c.JSON(http.StatusOK, value)
}
func welcome(c *echo.Context) error {
return c.String(http.StatusOK, fmt.Sprintf("正在用Go重写...... %v\n", time.Now()))
}
func ping(c *echo.Context) error {
return okJSON(c, "pong")
}
func main() {
//runtime.GOMAXPROCS(runtime.NumCPU())
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Use(mw.Gzip())
e.Get("/", welcome)
e.Get("/ping", ping)
//// Start server
//e.Run(":1323")
// Get the http.Server
s := e.Server(":8000")
// HTTP2 is currently enabled by default in echo.New(). To override TLS handshake errors
// you will need to override the TLSConfig for the server so it does not attempt to validate
// the connection using TLS as required by HTTP2
s.TLSConfig = nil
// Serve it like a boss
log.Fatal(gracehttp.Serve(s))
}