Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(778)

Unified Diff: service/taskqueue/context.go

Issue 1270063003: Make the rest of the services have a similar raw/user interface structure. (Closed) Base URL: https://github.com/luci/gae.git@add_datastore
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: service/taskqueue/context.go
diff --git a/service/taskqueue/context.go b/service/taskqueue/context.go
index ca195fb062206cafeb516f0b6d5e2af7fcc3c0c6..160f6b9d269914abc299267cb26e8055b8c44657 100644
--- a/service/taskqueue/context.go
+++ b/service/taskqueue/context.go
@@ -15,26 +15,26 @@ var (
taskQueueFilterKey key = 1
)
-// Factory is the function signature for factory methods compatible with
-// SetFactory.
-type Factory func(context.Context) Interface
+// RawFactory is the function signature for RawFactory methods compatible with
+// SetRawFactory.
+type RawFactory func(context.Context) RawInterface
-// Filter is the function signature for a filter TQ implementation. It
+// RawFilter is the function signature for a RawFilter TQ implementation. It
// gets the current TQ implementation, and returns a new TQ implementation
// backed by the one passed in.
-type Filter func(context.Context, Interface) Interface
+type RawFilter func(context.Context, RawInterface) RawInterface
-// getUnfiltered gets gets the Interface implementation from context without
+// getUnfiltered gets gets the RawInterface implementation from context without
// any of the filters applied.
-func getUnfiltered(c context.Context) Interface {
- if f, ok := c.Value(taskQueueKey).(Factory); ok && f != nil {
+func getUnfiltered(c context.Context) RawInterface {
+ if f, ok := c.Value(taskQueueKey).(RawFactory); ok && f != nil {
return f(c)
}
return nil
}
-// Get gets the Interface implementation from context.
-func Get(c context.Context) Interface {
+// GetRaw gets the RawInterface implementation from context.
+func GetRaw(c context.Context) RawInterface {
ret := getUnfiltered(c)
if ret == nil {
return nil
@@ -45,34 +45,34 @@ func Get(c context.Context) Interface {
return ret
}
-// SetFactory sets the function to produce Interface instances, as returned by
-// the Get method.
-func SetFactory(c context.Context, tqf Factory) context.Context {
+// SetRawFactory sets the function to produce RawInterface instances, as returned by
+// the GetRaw method.
+func SetRawFactory(c context.Context, tqf RawFactory) context.Context {
return context.WithValue(c, taskQueueKey, tqf)
}
-// Set sets the current Interface object in the context. Useful for testing
-// with a quick mock. This is just a shorthand SetFactory invocation to set
-// a factory which always returns the same object.
-func Set(c context.Context, tq Interface) context.Context {
- return SetFactory(c, func(context.Context) Interface { return tq })
+// SetRaw sets the current RawInterface object in the context. Useful for testing
+// with a quick mock. This is just a shorthand SetRawFactory invocation to SetRaw
+// a RawFactory which always returns the same object.
+func SetRaw(c context.Context, tq RawInterface) context.Context {
+ return SetRawFactory(c, func(context.Context) RawInterface { return tq })
}
-func getCurFilters(c context.Context) []Filter {
+func getCurFilters(c context.Context) []RawFilter {
curFiltsI := c.Value(taskQueueFilterKey)
if curFiltsI != nil {
- return curFiltsI.([]Filter)
+ return curFiltsI.([]RawFilter)
}
return nil
}
-// AddFilters adds Interface filters to the context.
-func AddFilters(c context.Context, filts ...Filter) context.Context {
+// AddRawFilters adds RawInterface filters to the context.
+func AddRawFilters(c context.Context, filts ...RawFilter) context.Context {
if len(filts) == 0 {
return c
}
cur := getCurFilters(c)
- newFilts := make([]Filter, 0, len(cur)+len(filts))
+ newFilts := make([]RawFilter, 0, len(cur)+len(filts))
newFilts = append(newFilts, getCurFilters(c)...)
newFilts = append(newFilts, filts...)
return context.WithValue(c, taskQueueFilterKey, newFilts)

Powered by Google App Engine
This is Rietveld 408576698