-
Notifications
You must be signed in to change notification settings - Fork 0
/
whoAmI.go
50 lines (35 loc) · 946 Bytes
/
whoAmI.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
package web
import (
"net/http"
"github.com/thijzert/chesseract/chesseract/game"
)
var WhoAmIHandler whoAmIHandler
type whoAmIHandler struct{}
type whoAmIRequest struct {
}
// The WhoAmIResponse wraps a WhoAmIHandler API response
type WhoAmIResponse struct {
Profile game.Player `json:"profile"`
}
func (whoAmIHandler) handleWhoAmI(p Provider, r whoAmIRequest) (WhoAmIResponse, error) {
var rv WhoAmIResponse
player, err := p.Player()
if err != nil {
return rv, err
}
rv.Profile = player
return rv, nil
}
func (whoAmIHandler) DecodeRequest(r *http.Request) (Request, error) {
return whoAmIRequest{}, nil
}
// Below: boilerplate code
func (h whoAmIHandler) HandleRequest(p Provider, r Request) (Response, error) {
req, ok := r.(whoAmIRequest)
if !ok {
return withError(errWrongRequestType{})
}
return h.handleWhoAmI(p, req)
}
func (whoAmIRequest) FlaggedAsRequest() {}
func (WhoAmIResponse) FlaggedAsResponse() {}