Browse Source

Updated sleepy to 6c9daa1e5c and changed handlers to new API.

pull/28/head
Simon Eisenmann 11 years ago committed by Simon Eisenmann
parent
commit
00dbdcee0f
  1. 3
      src/app/spreed-speakfreely-server/rooms.go
  2. 35
      src/app/spreed-speakfreely-server/sleepy/core.go
  3. 5
      src/app/spreed-speakfreely-server/stats.go
  4. 5
      src/app/spreed-speakfreely-server/tokens.go

3
src/app/spreed-speakfreely-server/rooms.go

@ -24,7 +24,6 @@ package main
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"net/url"
) )
type Room struct { type Room struct {
@ -35,7 +34,7 @@ type Room struct {
type Rooms struct { type Rooms struct {
} }
func (rooms *Rooms) Post(values url.Values, headers http.Header) (int, interface{}, http.Header) { func (rooms *Rooms) Post(request *http.Request) (int, interface{}, http.Header) {
name := NewRandomString(11) name := NewRandomString(11)
return 200, &Room{name, fmt.Sprintf("/%s", name)}, http.Header{"Content-Type": {"application/json"}} return 200, &Room{name, fmt.Sprintf("/%s", name)}, http.Header{"Content-Type": {"application/json"}}

35
src/app/spreed-speakfreely-server/sleepy/core.go

@ -35,7 +35,6 @@ import (
"fmt" "fmt"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"net/http" "net/http"
"net/url"
) )
const ( const (
@ -43,30 +42,44 @@ const (
POST = "POST" POST = "POST"
PUT = "PUT" PUT = "PUT"
DELETE = "DELETE" DELETE = "DELETE"
HEAD = "HEAD"
PATCH = "PATCH"
) )
// GetSupported is the interface that provides the Get // GetSupported is the interface that provides the Get
// method a resource must support to receive HTTP GETs. // method a resource must support to receive HTTP GETs.
type GetSupported interface { type GetSupported interface {
Get(url.Values, http.Header) (int, interface{}, http.Header) Get(*http.Request) (int, interface{}, http.Header)
} }
// PostSupported is the interface that provides the Post // PostSupported is the interface that provides the Post
// method a resource must support to receive HTTP POSTs. // method a resource must support to receive HTTP POSTs.
type PostSupported interface { type PostSupported interface {
Post(url.Values, http.Header) (int, interface{}, http.Header) Post(*http.Request) (int, interface{}, http.Header)
} }
// PutSupported is the interface that provides the Put // PutSupported is the interface that provides the Put
// method a resource must support to receive HTTP PUTs. // method a resource must support to receive HTTP PUTs.
type PutSupported interface { type PutSupported interface {
Put(url.Values, http.Header) (int, interface{}, http.Header) Put(*http.Request) (int, interface{}, http.Header)
} }
// DeleteSupported is the interface that provides the Delete // DeleteSupported is the interface that provides the Delete
// method a resource must support to receive HTTP DELETEs. // method a resource must support to receive HTTP DELETEs.
type DeleteSupported interface { type DeleteSupported interface {
Delete(url.Values, http.Header) (int, interface{}, http.Header) Delete(*http.Request) (int, interface{}, http.Header)
}
// HeadSupported is the interface that provides the Head
// method a resource must support to receive HTTP HEADs.
type HeadSupported interface {
Head(*http.Request) (int, interface{}, http.Header)
}
// PatchSupported is the interface that provides the Patch
// method a resource must support to receive HTTP PATCHs.
type PatchSupported interface {
Patch(*http.Request) (int, interface{}, http.Header)
} }
// Interface for arbitrary muxer support (like http.ServeMux). // Interface for arbitrary muxer support (like http.ServeMux).
@ -99,7 +112,7 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
return return
} }
var handler func(url.Values, http.Header) (int, interface{}, http.Header) var handler func(*http.Request) (int, interface{}, http.Header)
switch request.Method { switch request.Method {
case GET: case GET:
@ -118,6 +131,14 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
if resource, ok := resource.(DeleteSupported); ok { if resource, ok := resource.(DeleteSupported); ok {
handler = resource.Delete handler = resource.Delete
} }
case HEAD:
if resource, ok := resource.(HeadSupported); ok {
handler = resource.Head
}
case PATCH:
if resource, ok := resource.(PatchSupported); ok {
handler = resource.Patch
}
} }
if handler == nil { if handler == nil {
@ -125,7 +146,7 @@ func (api *API) requestHandler(resource interface{}) http.HandlerFunc {
return return
} }
code, data, header := handler(request.Form, request.Header) code, data, header := handler(request)
content, err := json.MarshalIndent(data, "", " ") content, err := json.MarshalIndent(data, "", " ")
if err != nil { if err != nil {

5
src/app/spreed-speakfreely-server/stats.go

@ -23,7 +23,6 @@ package main
import ( import (
"net/http" "net/http"
"net/url"
"runtime" "runtime"
"time" "time"
) )
@ -73,9 +72,9 @@ type Stats struct {
hub *Hub hub *Hub
} }
func (stats *Stats) Get(values url.Values, headers http.Header) (int, interface{}, http.Header) { func (stats *Stats) Get(request *http.Request) (int, interface{}, http.Header) {
details := values.Get("details") == "1" details := request.Form.Get("details") == "1"
return 200, NewStat(details, stats.hub), http.Header{"Content-Type": {"application/json; charset=utf-8"}, "Access-Control-Allow-Origin": {"*"}} return 200, NewStat(details, stats.hub), http.Header{"Content-Type": {"application/json; charset=utf-8"}, "Access-Control-Allow-Origin": {"*"}}
} }

5
src/app/spreed-speakfreely-server/tokens.go

@ -24,7 +24,6 @@ package main
import ( import (
"log" "log"
"net/http" "net/http"
"net/url"
"strings" "strings"
) )
@ -37,9 +36,9 @@ type Tokens struct {
provider TokenProvider provider TokenProvider
} }
func (tokens Tokens) Post(values url.Values, headers http.Header) (int, interface{}, http.Header) { func (tokens Tokens) Post(request *http.Request) (int, interface{}, http.Header) {
auth := values.Get("a") auth := request.Form.Get("a")
if len(auth) > 100 { if len(auth) > 100 {
return 413, NewApiError("auth_too_large", "Auth too large"), nil return 413, NewApiError("auth_too_large", "Auth too large"), nil

Loading…
Cancel
Save