-
Notifications
You must be signed in to change notification settings - Fork 1
/
web.go
53 lines (43 loc) · 1.31 KB
/
web.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
52
53
package web
import (
"net/http"
"github.com/thijzert/speeldoos/lib/wavreader/chunker"
speeldoos "github.com/thijzert/speeldoos/pkg"
)
// The State struct represents the current state of the world
type State struct {
Library *speeldoos.Library
NowPlaying speeldoos.Performance
RawStream chunker.Chunker
MP3Stream chunker.Chunker
Buffers struct {
Scheduler chunker.Statuser
MP3Stream chunker.Statuser
}
}
var (
// ErrParser is thrown when a request object is of the wrong type
ErrParser error = errParse{}
)
type errParse struct{}
func (errParse) Error() string {
return "parse error while decoding request"
}
// A Request flags any request type
type Request interface {
FlaggedAsRequest()
}
// A Response flags any response type
type Response interface {
FlaggedAsResponse()
}
// A Handler handles requests
type Handler interface {
// DecodeRequest turns a HTTP request into a domain-specific request type
DecodeRequest(*http.Request) (Request, error)
// A RequestHandler is a monadic definition of a request handler. The inputs
// are the current state of the world, and a handler-specific request type,
// and the output is the new state of the world (which may or may not be the
// same), a handler-specific response type, and/or an error.
HandleRequest(State, Request) (State, Response, error)
}