|
@@ -1,6 +1,7 @@
|
|
package rest
|
|
package rest
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "context"
|
|
"fmt"
|
|
"fmt"
|
|
"git.nspix.com/golang/micro/gateway/http"
|
|
"git.nspix.com/golang/micro/gateway/http"
|
|
"git.nspix.com/golang/micro/log"
|
|
"git.nspix.com/golang/micro/log"
|
|
@@ -26,6 +27,12 @@ type (
|
|
Value string `json:"value"`
|
|
Value string `json:"value"`
|
|
Children []*treeValue `json:"children"`
|
|
Children []*treeValue `json:"children"`
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ contextKey struct{}
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+var (
|
|
|
|
+ ctxKey = contextKey{}
|
|
)
|
|
)
|
|
|
|
|
|
func (t *treeValue) Append(v *treeValue) {
|
|
func (t *treeValue) Append(v *treeValue) {
|
|
@@ -272,3 +279,14 @@ func Dialer(cfg *Config) (crud *CRUD, err error) {
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func FromContext(ctx context.Context) *CRUD {
|
|
|
|
+ if v := ctx.Value(ctxKey); v != nil {
|
|
|
|
+ return v.(*CRUD)
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func WithContext(ctx context.Context, r *CRUD) context.Context {
|
|
|
|
+ return context.WithValue(ctx, ctxKey, r)
|
|
|
|
+}
|