mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add a GetString helper for simple string annotations. Add tests which call Get and GetString on annotations objects (#1118)
This commit is contained in:
@@ -160,6 +160,18 @@ func (m Annotations) Get(key string) ([]byte, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// GetString returns a string value if the annotation value is a string, otherwise an error
|
||||
func (m Annotations) GetString(key string) (string, error) {
|
||||
if v, ok := m[key]; ok {
|
||||
var s string
|
||||
if err := json.Unmarshal([]byte(*v), &s); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
return "", errors.New("Annotation not found")
|
||||
}
|
||||
|
||||
// Without returns a new annotations object with a value excluded
|
||||
func (m Annotations) Without(key string) Annotations {
|
||||
nuVal := m.clone()
|
||||
|
||||
Reference in New Issue
Block a user