Skip to content

Commit bc4a144

Browse files
committed
Add Get method to Dict and ParamList
1 parent b148d59 commit bc4a144

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Project files
2+
.idea/
3+
.vscode/
4+
5+
# Junks
6+
.DS_Store
7+
*.swp
8+
*~
9+
tmp/
10+
11+
# Vendor dependencies
12+
vendor/

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Go-SF
2+
3+
Go-SF is a Go implementation of IETF "Structured Field Values for HTTP" standard ([RFC8941](https://www.rfc-editor.org/rfc/rfc8941.html)).
4+
5+
## License
6+
7+
```
8+
MIT License
9+
10+
Copyright (c) 2023 HTTP Message Signatures
11+
12+
Permission is hereby granted, free of charge, to any person obtaining a copy
13+
of this software and associated documentation files (the "Software"), to deal
14+
in the Software without restriction, including without limitation the rights
15+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16+
copies of the Software, and to permit persons to whom the Software is
17+
furnished to do so, subject to the following conditions:
18+
19+
The above copyright notice and this permission notice shall be included in all
20+
copies or substantial portions of the Software.
21+
22+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28+
SOFTWARE.
29+
```

package.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// Package sf is an implementation of IETF standard RFC8941, "Structured Field
2-
// Values for HTTP".
1+
// Package sf is an implementation of IETF "Structured Field Values for HTTP"
2+
// standard (https://www.rfc-editor.org/rfc/rfc8941.html).
33
package sf

type.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ func (d Dict) Add(k string, v Member) Dict {
5656
return d
5757
}
5858

59+
// Get retrieves a value from the dictionary by its key.
60+
func (d Dict) Get(k string) Member {
61+
for _, p := range d {
62+
if p.Key == k {
63+
return p.Value
64+
}
65+
}
66+
return nil
67+
}
68+
5969
// Pair is a key-value pair in a dictionary.
6070
type Pair struct {
6171
Key string
@@ -124,6 +134,16 @@ func (l ParamList) Add(k string, v BareItem) ParamList {
124134
return l
125135
}
126136

137+
// Get retrieves a parameter value from the list by its key.
138+
func (l ParamList) Get(k string) BareItem {
139+
for _, p := range l {
140+
if p.Key == k {
141+
return p.Value
142+
}
143+
}
144+
return nil
145+
}
146+
127147
// Encode serializes the parameter list.
128148
func (l ParamList) Encode() string {
129149
if len(l) == 0 {

0 commit comments

Comments
 (0)