Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
davemeehan committed Jul 15, 2011
1 parent 51d8572 commit 6ae37f1
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions neo4j.go
Expand Up @@ -41,7 +41,7 @@ type Neo4j struct {
type Error struct {
List map[int]os.Error
Code int
Msg os.Error // used for general errors
Msg os.Error // used for general errors
}
// used when storing data returned from neo4j
type NeoTemplate struct {
Expand Down Expand Up @@ -86,14 +86,14 @@ func (this *Neo4j) GetProperty(id uint, name string) (string, os.Error) {
}
node, err := this.GetNode(id) // find properties for node
if err != nil {
return "", this.NewError(nil, err)
return "", this.NewError(nil, err)
}
this.Method = "get"
body, err := this.send(node.Properties+"/"+name, "")
if err != nil {
return "", this.NewError(nil, err)
return "", this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node or Property not found."),
204: os.NewError("No properties found."),
}
Expand All @@ -105,24 +105,24 @@ GetProperties(node id uint) returns a NeoTemplate struct and any errors raised
func (this *Neo4j) GetProperties(id uint) (tmp *NeoTemplate, err os.Error) {
node, err := this.GetNode(id) // find properties for node
if err != nil {
return tmp, this.NewError(nil, err)
return tmp, this.NewError(nil, err)
}
this.Method = "get"
body, err := this.send(node.Properties, "")
if err != nil {
return tmp, this.NewError(nil, err)
return tmp, this.NewError(nil, err)
}
// pack json string into variable "data" so the json unmarshaler knows where to put it on struct type NeoTemplate
jsonData, err := this.pack("data", body)
if err != nil {
return tmp, this.NewError(nil, err)
return tmp, this.NewError(nil, err)
}
//convert json -> string and unmarshal -> NeoTemplate
template, err := this.unmarshal(string(jsonData))
if err != nil {
return tmp, this.NewError(nil, err)
return tmp, this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node or Property not found."),
204: os.NewError("No properties found."),
}
Expand All @@ -135,31 +135,31 @@ typically replace should be false unless you wish to drop any other properties *
func (this *Neo4j) SetProperty(id uint, data map[string]string, replace bool) os.Error {
node, err := this.GetNode(id) // find properties for node
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
this.Method = "put"
s, err := json.Marshal(data)
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
if replace { // drop all properties on the node if they aren't specified in "data" ?
_, err := this.send(node.Properties, string(s))
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
} else {
for k, v := range data {
k = strings.TrimSpace(k) // strip leading & trailing whitespace from key
_, err := this.send(node.Properties+"/"+k, strconv.Quote(v)) // wrap value in double quotes as neo4j expects
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
}
}
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node not found."),
400: os.NewError("Invalid data sent."),
}
Expand All @@ -172,28 +172,28 @@ typically replace should be false unless you wish to drop any other properties *
func (this *Neo4j) CreateProperty(id uint, data map[string]string, replace bool) os.Error {
node, err := this.GetNode(id) // find properties for node
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
s, err := json.Marshal(data)
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
this.Method = "put"
if replace { // when replacing and dropping *ALL* values on node(not just new ones) we can simply pass in the entire json data set and neo4j will remove the old properties
_, err := this.send(node.Properties, string(s))
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
} else { // if we are keeping the other properties on the node we must pass in new properties 1 at a time
for k, v := range data {
k = strings.TrimSpace(k) // strip leading & trailing whitespace from key
_, err := this.send(node.Properties+"/"+k, strconv.Quote(v)) // wrap value in double quotes as neo4j expects
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
}
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node or Property not found."),
400: os.NewError("Invalid data sent."),
}
Expand All @@ -214,7 +214,7 @@ func (this *Neo4j) DelProperty(id uint, s string) os.Error {
if err != nil {
return this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node or Property not found."),
}
return this.NewError(errorList, nil)
Expand All @@ -232,7 +232,7 @@ func (this *Neo4j) DelNode(id uint) os.Error {
if err != nil {
return this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node not found."),
409: os.NewError("Unable to delete node. May still have relationships."),
}
Expand All @@ -250,13 +250,13 @@ func (this *Neo4j) CreateNode(data map[string]string) (tmp *NeoTemplate, err os.
url := this.URL + "/node"
body, err := this.send(url, string(s))
if err != nil {
return tmp, this.NewError(nil, err)
return tmp, this.NewError(nil, err)
}
template, err := this.unmarshal(body) // json.Unmarshal wrapper with some type assertions etc
if err != nil {
return tmp, this.NewError(nil, err)
return tmp, this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
400: os.NewError("Invalid data sent."),
}
return template[0], this.NewError(errorList, nil)
Expand All @@ -272,13 +272,13 @@ func (this *Neo4j) GetNode(id uint) (tmp *NeoTemplate, err os.Error) {
url := this.URL + "/node/"
body, err := this.send(url+strconv.Uitoa(id), "") // convert uint -> string and send http request
if err != nil {
return tmp, this.NewError(nil, err)
return tmp, this.NewError(nil, err)
}
template, err := this.unmarshal(body) // json.Unmarshal wrapper with some type assertions etc
if err != nil {
return tmp, this.NewError(nil, err)
return tmp, this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node not found."),
}
return template[0], this.NewError(errorList, nil)
Expand All @@ -289,7 +289,7 @@ GetRelationshipsOnNode(node id uint, name string, direction string) returns an a
func (this *Neo4j) GetRelationshipsOnNode(id uint, name string, direction string) (map[int]*NeoTemplate, os.Error) {
node, err := this.GetNode(id) // find properties for node
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
this.Method = "get"
direction = strings.ToLower(direction)
Expand All @@ -306,13 +306,13 @@ func (this *Neo4j) GetRelationshipsOnNode(id uint, name string, direction string
}
body, err := this.send(url+"/"+name, "")
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
template, err := this.unmarshal(body)
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node not found."),
}
return template, this.NewError(errorList, nil)
Expand All @@ -321,7 +321,7 @@ func (this *Neo4j) GetRelationshipsOnNode(id uint, name string, direction string
SetRelationship(relationship id uint, data map[string]string) returns any errors raised as os.Error
id is the relationship id
*/
func (this *Neo4j) SetRelationship(id uint, data map[string]string) (os.Error) {
func (this *Neo4j) SetRelationship(id uint, data map[string]string) os.Error {
this.Method = "put"
url := this.URL + "/relationship/"
s, err := json.Marshal(data)
Expand All @@ -330,9 +330,9 @@ func (this *Neo4j) SetRelationship(id uint, data map[string]string) (os.Error) {
}
_, err = this.send(url+strconv.Uitoa(id)+"/properties", string(s))
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Relationship not found."),
400: os.NewError("Invalid data sent."),
}
Expand All @@ -349,25 +349,25 @@ func (this *Neo4j) DelRelationship(id ...uint) os.Error {
// delete each relationship for every id passed in
_, err := this.send(url+strconv.Uitoa(i), "")
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Relationship not found."),
}
return this.NewError(errorList, nil)
}
/*
CreateRelationship(src node id uint, dst node id uint, data map[string]string, relationship type string) returns any errors raised as os.Error
*/
func (this *Neo4j) CreateRelationship(src uint, dst uint, data map[string]string, rType string) (os.Error) {
func (this *Neo4j) CreateRelationship(src uint, dst uint, data map[string]string, rType string) os.Error {
dstNode, err := this.GetNode(dst) // find properties for destination node so we can tie it into the relationship
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
srcNode, err := this.GetNode(src) // find properties for src node..
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
j := map[string]interface{}{} // empty map: keys are always strings in json, values vary
j["to"] = dstNode.Self
Expand All @@ -381,9 +381,9 @@ func (this *Neo4j) CreateRelationship(src uint, dst uint, data map[string]string
this.Method = "post"
_, err = this.send(srcNode.RelationshipsCreate, string(s)) // srcNode.RelationshipsCreate actually contains the full URL
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node or 'to' node not found."),
400: os.NewError("Invalid data sent."),
}
Expand Down Expand Up @@ -411,13 +411,13 @@ func (this *Neo4j) SearchIdx(key string, value string, query string, cat string,
this.Method = "get"
body, err := this.send(url, "")
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
template, err := this.unmarshal(body)
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
400: os.NewError("Invalid data sent."),
}
return template, this.NewError(errorList, nil)
Expand All @@ -426,10 +426,10 @@ func (this *Neo4j) SearchIdx(key string, value string, query string, cat string,
/*
CreateIdx(node id uint, key string, value string, category string, index type string) returns any errors raised as os.Error
*/
func (this *Neo4j) CreateIdx(id uint, key string, value string, cat string, idxType string) (os.Error) {
func (this *Neo4j) CreateIdx(id uint, key string, value string, cat string, idxType string) os.Error {
template, err := this.GetNode(id)
if err != nil {
return this.NewError(nil, err)
return this.NewError(nil, err)
}
if len(cat) < 1 {
idxType = "idx_nodes" // default, generic, index type
Expand All @@ -444,7 +444,7 @@ func (this *Neo4j) CreateIdx(id uint, key string, value string, cat string, idxT
url += "/" + cat + "/" + key + "/" + value + "/"
this.Method = "post"
_, err = this.send(url, strconv.Quote(self)) // add double quotes around the node url as neo4j expects
errorList := map[int]os.Error {
errorList := map[int]os.Error{
400: os.NewError("Invalid data sent."),
}
return this.NewError(errorList, nil)
Expand All @@ -455,7 +455,7 @@ Traverse(node id uint, return type string, order string, uniqueness string, rela
func (this *Neo4j) Traverse(id uint, returnType string, order string, uniqueness string, relationships map[string]string, depth int, prune map[string]string, filter map[string]string) (map[int]*NeoTemplate, os.Error) {
node, err := this.GetNode(id) // find properties for destination node
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
j := map[string]interface{}{} // empty map: keys are always strings in json, values vary
j["order"] = order
Expand Down Expand Up @@ -490,13 +490,13 @@ func (this *Neo4j) Traverse(id uint, returnType string, order string, uniqueness
url := strings.Replace(node.Traverse, "{returnType}", returnType, 1) // neo4j returns the traverse URL with the literal "{returnType}" at the end
body, err := this.send(url, string(s))
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
template, err := this.unmarshal(body)
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("Node not found."),
}
return template, this.NewError(errorList, nil)
Expand All @@ -508,11 +508,11 @@ TraversePath(src node id uint, dst node id uint, relationships map[string]string
func (this *Neo4j) TraversePath(src uint, dst uint, relationships map[string]string, depth uint, algo string, paths bool) (map[int]*NeoTemplate, os.Error) {
dstNode, err := this.GetNode(dst) // find properties for destination node
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
srcNode, err := this.GetNode(src) // find properties for src node..
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
j := map[string]interface{}{} // empty map: keys are always strings in json, values vary
j["to"] = dstNode.Self
Expand All @@ -533,19 +533,19 @@ func (this *Neo4j) TraversePath(src uint, dst uint, relationships map[string]str
}
body, err := this.send(url, string(s))
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
template, err := this.unmarshal(body)
if err != nil {
return nil, this.NewError(nil, err)
return nil, this.NewError(nil, err)
}
errorList := map[int]os.Error {
errorList := map[int]os.Error{
404: os.NewError("No path found using current algorithm and parameters"),
}
return template, this.NewError(errorList, nil)
}
/* shamelessly taken from golang html pkg */
func (this *Neo4j) EscapeString(s string) (string) {
func (this *Neo4j) EscapeString(s string) string {
if strings.IndexAny(s, escapedChars) == -1 {
return s
}
Expand Down Expand Up @@ -593,7 +593,7 @@ func (this *Neo4j) escape(buf *bytes.Buffer, s string) {
}
// checks the status code of the http response and returns an appropriate error(or not).
// We have to switch based on which method is calling this function because certain HTTP status codes have different meanings depending on the specific REST operation.
func (this *Error) Check() (os.Error) {
func (this *Error) Check() os.Error {
if this.List != nil {
if this.List[this.Code] != nil {
this.Msg = this.List[this.Code]
Expand Down

0 comments on commit 6ae37f1

Please sign in to comment.