github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/google.golang.org/appengine/capability/capability.go (about) 1 // Copyright 2011 Google Inc. All rights reserved. 2 // Use of this source code is governed by the Apache 2.0 3 // license that can be found in the LICENSE file. 4 5 /* 6 Package capability exposes information about outages and scheduled downtime 7 for specific API capabilities. 8 9 This package does not work on Managed VMs. 10 11 Example: 12 if !capability.Enabled(c, "datastore_v3", "write") { 13 // show user a different page 14 } 15 */ 16 package capability 17 18 import ( 19 "golang.org/x/net/context" 20 21 "google.golang.org/appengine/internal" 22 "google.golang.org/appengine/log" 23 24 pb "google.golang.org/appengine/internal/capability" 25 ) 26 27 // Enabled returns whether an API's capabilities are enabled. 28 // The wildcard "*" capability matches every capability of an API. 29 // If the underlying RPC fails (if the package is unknown, for example), 30 // false is returned and information is written to the application log. 31 func Enabled(ctx context.Context, api, capability string) bool { 32 req := &pb.IsEnabledRequest{ 33 Package: &api, 34 Capability: []string{capability}, 35 } 36 res := &pb.IsEnabledResponse{} 37 if err := internal.Call(ctx, "capability_service", "IsEnabled", req, res); err != nil { 38 log.Warningf(ctx, "capability.Enabled: RPC failed: %v", err) 39 return false 40 } 41 switch *res.SummaryStatus { 42 case pb.IsEnabledResponse_ENABLED, 43 pb.IsEnabledResponse_SCHEDULED_FUTURE, 44 pb.IsEnabledResponse_SCHEDULED_NOW: 45 return true 46 case pb.IsEnabledResponse_UNKNOWN: 47 log.Errorf(ctx, "capability.Enabled: unknown API capability %s/%s", api, capability) 48 return false 49 default: 50 return false 51 } 52 }