go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/gae/impl/prod/module.go (about)

     1  // Copyright 2016 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package prod
    16  
    17  import (
    18  	"context"
    19  
    20  	aeModule "google.golang.org/appengine/module"
    21  
    22  	"go.chromium.org/luci/gae/service/module"
    23  )
    24  
    25  // useModule adds a Module implementation to context.
    26  func useModule(usrCtx context.Context) context.Context {
    27  	return module.SetFactory(usrCtx, func(ci context.Context) module.RawInterface {
    28  		return modImpl{getAEContext(ci)}
    29  	})
    30  }
    31  
    32  type modImpl struct {
    33  	aeCtx context.Context
    34  }
    35  
    36  func (m modImpl) List() ([]string, error) {
    37  	return aeModule.List(m.aeCtx)
    38  }
    39  
    40  func (m modImpl) NumInstances(module, version string) (int, error) {
    41  	return aeModule.NumInstances(m.aeCtx, module, version)
    42  }
    43  
    44  func (m modImpl) SetNumInstances(module, version string, instances int) error {
    45  	return aeModule.SetNumInstances(m.aeCtx, module, version, instances)
    46  }
    47  
    48  func (m modImpl) Versions(module string) ([]string, error) {
    49  	return aeModule.Versions(m.aeCtx, module)
    50  }
    51  
    52  func (m modImpl) DefaultVersion(module string) (string, error) {
    53  	return aeModule.DefaultVersion(m.aeCtx, module)
    54  }
    55  
    56  func (m modImpl) Start(module, version string) error {
    57  	return aeModule.Start(m.aeCtx, module, version)
    58  }
    59  
    60  func (m modImpl) Stop(module, version string) error {
    61  	return aeModule.Stop(m.aeCtx, module, version)
    62  }