-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.go
46 lines (37 loc) · 844 Bytes
/
box.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
package box
import (
"fmt"
"net/http"
"os"
)
type B struct {
// R is the root resource in box
*R
HttpHandler http.Handler
}
func (b *B) ServeHTTP(w http.ResponseWriter, r *http.Request) {
b.HttpHandler.ServeHTTP(w, r)
}
func NewBox() *B {
b := &B{
R: NewResource(),
}
b.HttpHandler = Box2Http(b)
return b
}
// Serve is a helper that creates a new http.Server and call to its method
// ListenAndServe on address :8080
// Deprecated: Use the analogous name b.ListenAndServe
func (b *B) Serve() {
b.ListenAndServe()
}
// ListenAndServe is a helper that creates a new http.Server and call to its
// method ListenAndServe on address :8080
func (b *B) ListenAndServe() error {
server := &http.Server{
Addr: ":8080",
Handler: b,
}
fmt.Fprintln(os.Stderr, "Listening to", server.Addr)
return server.ListenAndServe()
}