Skip to content

Commit fbb40f3

Browse files
committed
use .Find() instead of .GetFirst() everywhere.
1 parent d97a2f1 commit fbb40f3

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

blossom/handlers.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (bs BlossomServer) handleUploadCheck(w http.ResponseWriter, r *http.Request
2525
blossomError(w, "missing \"Authorization\" header", 401)
2626
return
2727
}
28-
if auth.Tags.GetFirst([]string{"t", "upload"}) == nil {
28+
if auth.Tags.FindWithValue("t", "upload") == nil {
2929
blossomError(w, "invalid \"Authorization\" event \"t\" tag", 403)
3030
return
3131
}
@@ -59,7 +59,7 @@ func (bs BlossomServer) handleUpload(w http.ResponseWriter, r *http.Request) {
5959
blossomError(w, "missing \"Authorization\" header", 401)
6060
return
6161
}
62-
if auth.Tags.GetFirst([]string{"t", "upload"}) == nil {
62+
if auth.Tags.FindWithValue("t", "upload") == nil {
6363
blossomError(w, "invalid \"Authorization\" event \"t\" tag", 403)
6464
return
6565
}
@@ -163,13 +163,13 @@ func (bs BlossomServer) handleGetBlob(w http.ResponseWriter, r *http.Request) {
163163

164164
// if there is one, we check if it has the extra requirements
165165
if auth != nil {
166-
if auth.Tags.GetFirst([]string{"t", "get"}) == nil {
166+
if auth.Tags.FindWithValue("t", "get") == nil {
167167
blossomError(w, "invalid \"Authorization\" event \"t\" tag", 403)
168168
return
169169
}
170170

171-
if auth.Tags.GetFirst([]string{"x", hhash}) == nil &&
172-
auth.Tags.GetFirst([]string{"server", bs.ServiceURL}) == nil {
171+
if auth.Tags.FindWithValue("x", hhash) == nil &&
172+
auth.Tags.FindWithValue("server", bs.ServiceURL) == nil {
173173
blossomError(w, "invalid \"Authorization\" event \"x\" or \"server\" tag", 403)
174174
return
175175
}
@@ -239,7 +239,7 @@ func (bs BlossomServer) handleList(w http.ResponseWriter, r *http.Request) {
239239

240240
// if there is one, we check if it has the extra requirements
241241
if auth != nil {
242-
if auth.Tags.GetFirst([]string{"t", "list"}) == nil {
242+
if auth.Tags.FindWithValue("t", "list") == nil {
243243
blossomError(w, "invalid \"Authorization\" event \"t\" tag", 403)
244244
return
245245
}
@@ -283,7 +283,7 @@ func (bs BlossomServer) handleDelete(w http.ResponseWriter, r *http.Request) {
283283
}
284284

285285
if auth != nil {
286-
if auth.Tags.GetFirst([]string{"t", "delete"}) == nil {
286+
if auth.Tags.FindWithValue("t", "delete") == nil {
287287
blossomError(w, "invalid \"Authorization\" event \"t\" tag", 403)
288288
return
289289
}
@@ -296,8 +296,8 @@ func (bs BlossomServer) handleDelete(w http.ResponseWriter, r *http.Request) {
296296
return
297297
}
298298
hhash = hhash[1:]
299-
if auth.Tags.GetFirst([]string{"x", hhash}) == nil &&
300-
auth.Tags.GetFirst([]string{"server", bs.ServiceURL}) == nil {
299+
if auth.Tags.FindWithValue("x", hhash) == nil &&
300+
auth.Tags.FindWithValue("server", bs.ServiceURL) == nil {
301301
blossomError(w, "invalid \"Authorization\" event \"x\" or \"server\" tag", 403)
302302
return
303303
}

docs/core/routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ router.Route().
4747
return true
4848
case event.Kind <= 12 && event.Kind >= 9:
4949
return true
50-
case event.Tags.GetFirst([]string{"h", ""}) != nil:
50+
case event.Tags.Find("h") != nil:
5151
return true
5252
default:
5353
return false

examples/routing/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func main() {
5252
return slices.Contains(filter.Kinds, 1) && slices.Contains(filter.Tags["t"], "spam")
5353
}).
5454
Event(func(event *nostr.Event) bool {
55-
return event.Kind == 1 && event.Tags.GetFirst([]string{"t", "spam"}) != nil
55+
return event.Kind == 1 && event.Tags.FindWithValue("t", "spam") != nil
5656
}).
5757
Relay(r2)
5858

nip86.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request) {
8686
goto respond
8787
}
8888

89-
if uTag := evt.Tags.GetFirst([]string{"u", ""}); uTag == nil || rl.getBaseURL(r) != (*uTag)[1] {
89+
if uTag := evt.Tags.Find("u"); uTag == nil || rl.getBaseURL(r) != uTag[1] {
9090
resp.Error = "invalid 'u' tag"
9191
goto respond
92-
} else if pht := evt.Tags.GetFirst([]string{"payload", hex.EncodeToString(payloadHash[:])}); pht == nil {
92+
} else if pht := evt.Tags.FindWithValue("payload", hex.EncodeToString(payloadHash[:])); pht == nil {
9393
resp.Error = "invalid auth event payload hash"
9494
goto respond
9595
} else if evt.CreatedAt < nostr.Now()-30 {

0 commit comments

Comments
 (0)