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

Unified Diff: impl/memory/module.go

Issue 1772943003: Add wrappers for the module module (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: CL comments Created 4 years, 9 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
« no previous file with comments | « impl/memory/context.go ('k') | impl/memory/module_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/module.go
diff --git a/impl/memory/module.go b/impl/memory/module.go
new file mode 100644
index 0000000000000000000000000000000000000000..253fe1476f9cf4a1b4c99bd186b326f53b61ba14
--- /dev/null
+++ b/impl/memory/module.go
@@ -0,0 +1,64 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package memory
+
+import (
+ "github.com/luci/gae/service/module"
+ "golang.org/x/net/context"
+)
+
+type modContextKeyType int
+
+var modContextKey modContextKeyType
+
+type moduleVersion struct {
+ module, version string
+}
+
+type modImpl struct {
+ c context.Context
+ numInstances map[moduleVersion]int
+}
+
+// useMod adds a Module interface to the context
+func useMod(c context.Context) context.Context {
+ return module.SetFactory(c, func(ic context.Context) module.Interface {
+ return &modImpl{ic, map[moduleVersion]int{}}
+ })
+}
+
+var _ = module.Interface((*modImpl)(nil))
+
+func (mod *modImpl) List() ([]string, error) {
+ return []string{"testModule1", "testModule2"}, nil
+}
+
+func (mod *modImpl) NumInstances(module, version string) (int, error) {
+ if ret, ok := mod.numInstances[moduleVersion{module, version}]; ok {
+ return ret, nil
+ }
+ return 1, nil
+}
+
+func (mod *modImpl) SetNumInstances(module, version string, instances int) error {
+ mod.numInstances[moduleVersion{module, version}] = instances
+ return nil
+}
+
+func (mod *modImpl) Versions(module string) ([]string, error) {
+ return []string{"testVersion1", "testVersion2"}, nil
+}
+
+func (mod *modImpl) DefaultVersion(module string) (string, error) {
+ return "testVersion1", nil
+}
+
+func (mod *modImpl) Start(module, version string) error {
+ return nil
+}
+
+func (mod *modImpl) Stop(module, version string) error {
+ return nil
+}
« no previous file with comments | « impl/memory/context.go ('k') | impl/memory/module_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698