OLD | NEW |
(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 } |
OLD | NEW |