reduce nesting with early returns
This commit is contained in:
parent
f502872a48
commit
64c45abc74
40
web.go
40
web.go
|
@ -343,7 +343,10 @@ func inbox(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("pong from %s: %s", who, obj)
|
log.Printf("pong from %s: %s", who, obj)
|
||||||
case "Follow":
|
case "Follow":
|
||||||
obj, _ := j.GetString("object")
|
obj, _ := j.GetString("object")
|
||||||
if obj == user.URL {
|
if obj != user.URL {
|
||||||
|
log.Printf("can't follow %s", obj)
|
||||||
|
return
|
||||||
|
}
|
||||||
log.Printf("updating honker follow: %s", who)
|
log.Printf("updating honker follow: %s", who)
|
||||||
|
|
||||||
db := opendatabase()
|
db := opendatabase()
|
||||||
|
@ -360,9 +363,6 @@ func inbox(w http.ResponseWriter, r *http.Request) {
|
||||||
stmtSaveDub.Exec(user.ID, who, who, "dub")
|
stmtSaveDub.Exec(user.ID, who, who, "dub")
|
||||||
}
|
}
|
||||||
go rubadubdub(user, j)
|
go rubadubdub(user, j)
|
||||||
} else {
|
|
||||||
log.Printf("can't follow %s", obj)
|
|
||||||
}
|
|
||||||
case "Accept":
|
case "Accept":
|
||||||
log.Printf("updating honker accept: %s", who)
|
log.Printf("updating honker accept: %s", who)
|
||||||
_, err = stmtUpdateFlavor.Exec("sub", user.ID, who, "presub")
|
_, err = stmtUpdateFlavor.Exec("sub", user.ID, who, "presub")
|
||||||
|
@ -394,7 +394,8 @@ func inbox(w http.ResponseWriter, r *http.Request) {
|
||||||
obj, ok := j.GetMap("object")
|
obj, ok := j.GetMap("object")
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("unknown undo no object")
|
log.Printf("unknown undo no object")
|
||||||
} else {
|
return
|
||||||
|
}
|
||||||
what, _ := obj.GetString("type")
|
what, _ := obj.GetString("type")
|
||||||
switch what {
|
switch what {
|
||||||
case "Follow":
|
case "Follow":
|
||||||
|
@ -411,7 +412,6 @@ func inbox(w http.ResponseWriter, r *http.Request) {
|
||||||
default:
|
default:
|
||||||
log.Printf("unknown undo: %s", what)
|
log.Printf("unknown undo: %s", what)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
go xonksaver(user, j, origin)
|
go xonksaver(user, j, origin)
|
||||||
}
|
}
|
||||||
|
@ -469,7 +469,10 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m := re_ont.FindStringSubmatch(obj)
|
m := re_ont.FindStringSubmatch(obj)
|
||||||
if len(m) == 2 {
|
if len(m) != 2 {
|
||||||
|
log.Printf("not sure how to handle this")
|
||||||
|
return
|
||||||
|
}
|
||||||
ont := "#" + m[1]
|
ont := "#" + m[1]
|
||||||
log.Printf("%s wants to follow %s", who, ont)
|
log.Printf("%s wants to follow %s", who, ont)
|
||||||
db := opendatabase()
|
db := opendatabase()
|
||||||
|
@ -486,20 +489,22 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
|
||||||
stmtSaveDub.Exec(user.ID, ont, who, "dub")
|
stmtSaveDub.Exec(user.ID, ont, who, "dub")
|
||||||
}
|
}
|
||||||
go rubadubdub(user, j)
|
go rubadubdub(user, j)
|
||||||
} else {
|
|
||||||
log.Printf("not sure how to handle this")
|
|
||||||
}
|
|
||||||
case "Undo":
|
case "Undo":
|
||||||
obj, ok := j.GetMap("object")
|
obj, ok := j.GetMap("object")
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("unknown undo no object")
|
log.Printf("unknown undo no object")
|
||||||
} else {
|
return
|
||||||
|
}
|
||||||
what, _ := obj.GetString("type")
|
what, _ := obj.GetString("type")
|
||||||
switch what {
|
if what != "Follow" {
|
||||||
case "Follow":
|
log.Printf("unknown undo: %s", what)
|
||||||
|
}
|
||||||
targ, _ := obj.GetString("object")
|
targ, _ := obj.GetString("object")
|
||||||
m := re_ont.FindStringSubmatch(targ)
|
m := re_ont.FindStringSubmatch(targ)
|
||||||
if len(m) == 2 {
|
if len(m) != 2 {
|
||||||
|
log.Printf("not sure how to handle this")
|
||||||
|
return
|
||||||
|
}
|
||||||
ont := "#" + m[1]
|
ont := "#" + m[1]
|
||||||
log.Printf("updating honker undo: %s", who, ont)
|
log.Printf("updating honker undo: %s", who, ont)
|
||||||
_, err = stmtUpdateFlavor.Exec("undub", user.ID, who, ont, "dub")
|
_, err = stmtUpdateFlavor.Exec("undub", user.ID, who, ont, "dub")
|
||||||
|
@ -507,13 +512,6 @@ func serverinbox(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("error updating honker: %s", err)
|
log.Printf("error updating honker: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
log.Printf("not sure how to handle this")
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
log.Printf("unknown undo: %s", what)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue