-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
44 lines (38 loc) · 939 Bytes
/
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
package server
import (
"context"
"fmt"
"log"
"net"
"net/http"
"os"
"time"
)
type Server struct {
httpServer *http.Server
}
func (s *Server) RunHttp(port string, handler http.Handler) error {
logger := log.New(os.Stdout, "WARNING: ", log.Ldate|log.Ltime|log.Lshortfile)
s.httpServer = &http.Server{
Addr: ":" + port,
Handler: handler,
TLSConfig: nil,
ReadTimeout: 10 * time.Second,
ReadHeaderTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
//ConnState: fConnState,
ErrorLog: logger,
//BaseContext: nil,
//ConnContext: nil,
}
return s.httpServer.ListenAndServe()
}
func fConnState(n net.Conn, state http.ConnState) {
fmt.Println("ConnState")
fmt.Println(n, state)
}
func (s *Server) Shutdown(ctx context.Context) error {
return s.httpServer.Shutdown(ctx)
}