summaryrefslogtreecommitdiff
path: root/service/http/attributes.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-07 19:52:46 -0700
committerWolfy-J <[email protected]>2018-07-07 19:52:46 -0700
commitb819c830c407fb4c8bec21c3a3891a8313db7a8e (patch)
treef69e8e5885f7feabb11b94a9b2b87182f6034d75 /service/http/attributes.go
parent806b89a1ac24cf6d173f697c9261eed5efa68c3f (diff)
more tests
Diffstat (limited to 'service/http/attributes.go')
-rw-r--r--service/http/attributes.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/service/http/attributes.go b/service/http/attributes.go
index fe069adf..3db538db 100644
--- a/service/http/attributes.go
+++ b/service/http/attributes.go
@@ -3,6 +3,7 @@ package http
import (
"context"
"net/http"
+ "github.com/go-errors/errors"
)
const contextKey = "psr:attributes"
@@ -18,7 +19,7 @@ func InitAttributes(r *http.Request) *http.Request {
func AllAttributes(r *http.Request) map[string]interface{} {
v := r.Context().Value(contextKey)
if v == nil {
- return nil
+ return attrs{}
}
return v.(attrs)
@@ -29,7 +30,7 @@ func AllAttributes(r *http.Request) map[string]interface{} {
func GetAttribute(r *http.Request, key string) interface{} {
v := r.Context().Value(contextKey)
if v == nil {
- return ""
+ return nil
}
return v.(attrs).Get(key)
@@ -37,9 +38,14 @@ func GetAttribute(r *http.Request, key string) interface{} {
// Set sets the key to value. It replaces any existing
// values. Context specific.
-func SetAttribute(r *http.Request, key string, value interface{}) {
+func SetAttribute(r *http.Request, key string, value interface{}) error {
v := r.Context().Value(contextKey)
+ if v == nil {
+ return errors.New("unable to find psr:attributes context value")
+ }
+
v.(attrs).Set(key, value)
+ return nil
}
// Get gets the value associated with the given key.
@@ -60,4 +66,4 @@ func (v attrs) Set(key string, value interface{}) {
// Del deletes the value associated with key.
func (v attrs) Del(key string) {
delete(v, key)
-} \ No newline at end of file
+}