changed public id format to be 128 bit length.

This commit is contained in:
didier amyot committed 2015-07-05 18:16:40 -04:00
1 parent 78d50d9a6d
commit d2cf9d7498
11 files changed
+187 -22

No files matched your search

+2 -2
View File
@@ -6,13 +6,13 @@ import (
)
func GetAllDoormen(w http.ResponseWriter, request *http.Request) {
fmt.Fprint(w, `{"doormen" :[`)
doormenIds := conn.GetAllDoormen()
buff := <-doormenIds
if buff == nil {
fmt.Fprint(w, "]}")
fmt.Fprint(w, `{"doormen" :[]}`)
return
}
fmt.Fprint(w, `{"doormen" :[`)
for doormanId := range doormenIds {
fmt.Fprint(w, getDoormenIdsAsJson(buff)+`,`)
buff = doormanId
+1 -1
View File
@@ -29,7 +29,7 @@ func TestGetAllDoormen(t *testing.T) {
GetAllDoormen(w, req)
d := json.NewDecoder(w.Body)
m := make(map[string][]*doormen.DoormanDefinition)
m := make(map[string][]*doormen.DoormanId)
if err := d.Decode(&m); err != nil {
t.Error(err)
+2 -1
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/didiercrunch/doormanserver/doormen"
"github.com/didiercrunch/doormanserver/shared"
"gopkg.in/mgo.v2/bson"
"net/http"
)
@@ -30,6 +31,6 @@ func CreateDoorman(w http.ResponseWriter, request *http.Request) {
return
}
go publisher.Emit(wdef.Id, wdef)
w.Header().Set("location", "/api/doormen/"+wdef.Id.Hex())
w.Header().Set("location", "/api/doormen/"+shared.ObjectIdToPublicId(wdef.Id))
w.WriteHeader(201)
}
+7 -1
View File
@@ -3,6 +3,7 @@ package api
import (
"bytes"
"github.com/didiercrunch/doormanserver/inmemoryconnector"
"github.com/didiercrunch/doormanserver/shared"
"gopkg.in/mgo.v2/bson"
"net/http"
"net/http/httptest"
@@ -11,7 +12,12 @@ import (
)
func GetIdFromLocation(p string) bson.ObjectId {
return bson.ObjectIdHex(path.Base(p))
if id, err := shared.PublicIdToObjectId(path.Base(p)); err != nil {
panic(err)
} else {
return id
}
}
func TestCreateDoorman(t *testing.T) {
+5 -3
View File
@@ -3,6 +3,7 @@ package api
import (
"fmt"
"github.com/didiercrunch/doormanserver/doormen"
"github.com/didiercrunch/doormanserver/shared"
"github.com/gorilla/mux"
"gopkg.in/mgo.v2/bson"
"log"
@@ -10,15 +11,16 @@ import (
)
func getDoormenIdsAsJson(id *doormen.DoormanId) string {
return fmt.Sprintf(`{"name": "%v", "id": "%v", "url": "/api/doormen/%v"}`, id.Name, id.Id.Hex(), id.Id.Hex())
publicId := shared.ObjectIdToPublicId(id.Id)
return fmt.Sprintf(`{"name": "%v", "id": "%v", "url": "/api/doormen/%v"}`, id.Name, publicId, publicId)
}
func getDoormanIdFromRequest(w http.ResponseWriter, request *http.Request) bson.ObjectId {
id := mux.Vars(request)["id"]
if !bson.IsObjectIdHex(id) {
if id, err := shared.PublicIdToObjectId(id); err != nil {
return ""
} else {
return bson.ObjectIdHex(id)
return id
}
}