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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « impl/memory/context.go ('k') | impl/memory/module_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package memory
6
7 import (
8 "github.com/luci/gae/service/module"
9 "golang.org/x/net/context"
10 )
11
12 type modContextKeyType int
13
14 var modContextKey modContextKeyType
15
16 type moduleVersion struct {
17 module, version string
18 }
19
20 type modImpl struct {
21 c context.Context
22 numInstances map[moduleVersion]int
23 }
24
25 // useMod adds a Module interface to the context
26 func useMod(c context.Context) context.Context {
27 return module.SetFactory(c, func(ic context.Context) module.Interface {
28 return &modImpl{ic, map[moduleVersion]int{}}
29 })
30 }
31
32 var _ = module.Interface((*modImpl)(nil))
33
34 func (mod *modImpl) List() ([]string, error) {
35 return []string{"testModule1", "testModule2"}, nil
36 }
37
38 func (mod *modImpl) NumInstances(module, version string) (int, error) {
39 if ret, ok := mod.numInstances[moduleVersion{module, version}]; ok {
40 return ret, nil
41 }
42 return 1, nil
43 }
44
45 func (mod *modImpl) SetNumInstances(module, version string, instances int) error {
46 mod.numInstances[moduleVersion{module, version}] = instances
47 return nil
48 }
49
50 func (mod *modImpl) Versions(module string) ([]string, error) {
51 return []string{"testVersion1", "testVersion2"}, nil
52 }
53
54 func (mod *modImpl) DefaultVersion(module string) (string, error) {
55 return "testVersion1", nil
56 }
57
58 func (mod *modImpl) Start(module, version string) error {
59 return nil
60 }
61
62 func (mod *modImpl) Stop(module, version string) error {
63 return nil
64 }
OLDNEW
« 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