| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package application |
| 6 |
| 7 import ( |
| 8 "github.com/luci/luci-go/common/errors" |
| 9 |
| 10 "golang.org/x/net/context" |
| 11 ) |
| 12 |
| 13 var appKey = "github.com/luci/luci-go/vpython/application.A" |
| 14 |
| 15 func withConfig(c context.Context, cfg *Config) context.Context { |
| 16 return context.WithValue(c, &appKey, cfg) |
| 17 } |
| 18 |
| 19 func getConfig(c context.Context) *Config { |
| 20 return c.Value(&appKey).(*Config) |
| 21 } |
| 22 |
| 23 func run(c context.Context, fn func(context.Context) error) int { |
| 24 err := fn(c) |
| 25 |
| 26 switch t := errors.Unwrap(err).(type) { |
| 27 case nil: |
| 28 return 0 |
| 29 |
| 30 case ReturnCodeError: |
| 31 return int(t) |
| 32 |
| 33 default: |
| 34 errors.Log(c, err) |
| 35 return 1 |
| 36 } |
| 37 } |
| OLD | NEW |