-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathendpoint.go
More file actions
39 lines (29 loc) · 762 Bytes
/
endpoint.go
File metadata and controls
39 lines (29 loc) · 762 Bytes
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
package main
import (
"net/http"
"reflect"
"runtime"
log "github.com/golang/glog"
"github.com/gorilla/websocket"
)
var (
upgrader = &websocket.Upgrader{
// CheckOrigin: func(r *http.Request) bool { return true },
ReadBufferSize: 1024,
WriteBufferSize: 1024,
}
)
type handler func(http.ResponseWriter, *http.Request, *Context) error
type Context struct {
}
type Endpoint struct {
Serve handler
}
func (e Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := Context{}
handlerName := runtime.FuncForPC(reflect.ValueOf(e.Serve).Pointer()).Name()
log.Infof("%s %s [%s]", r.Method, r.URL.Path, handlerName)
if err := e.Serve(w, r, &ctx); err != nil {
log.Errorf("Error while executing %s: %v", handlerName, err)
}
}