Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(701)

Delta Between Two Patch Sets: environs/open.go

Issue 6215045: environs: add NewEnviron(kind, config) (Closed)
Left Patch Set: Created 12 years, 10 months ago
Right Patch Set: environs: add NewEnviron(kind, config) Created 12 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « environs/interface.go ('k') | environs/open_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package environs 1 package environs
2 2
3 import "fmt" 3 import "fmt"
4 4
5 // New creates a new Environ using the 5 // Open creates a new Environ using the environment configuration with the
6 // environment configuration with the given name. 6 // given name. If name is empty, the default environment will be used.
7 // If name is empty, the default environment will be used.
8 func (envs *Environs) Open(name string) (Environ, error) { 7 func (envs *Environs) Open(name string) (Environ, error) {
9 if name == "" { 8 if name == "" {
10 name = envs.Default 9 name = envs.Default
10 if name == "" {
11 return nil, fmt.Errorf("no default environment found")
12 }
13 }
14 e, ok := envs.environs[name]
15 if !ok {
16 return nil, fmt.Errorf("unknown environment %q", name)
17 }
18 if e.err != nil {
19 return nil, e.err
20 }
21 env, err := providers[e.kind].Open(name, e.config)
22 if err != nil {
23 return nil, fmt.Errorf("cannot initialize environment %q: %v", n ame, err)
24 }
25
26 return env, nil
27 }
28
29 // NewEnviron creates a new Environ of the registered kind using the configurati on
30 // supplied.
31 func NewEnviron(kind string, config map[string]interface{}) (Environ, error) {
32 p, ok := providers[kind]
33 if !ok {
34 return nil, fmt.Errorf("no registered provider for kind: %q", ki nd)
35 }
36 cfg, err := p.ConfigChecker().Coerce(config, nil)
37 if err != nil {
38 return nil, fmt.Errorf("error validating environment: %v", err)
39 }
40
41 // TODO(dfc) the name of the environment needs to be injected when it is······
42 // created from environments.yaml
43 return p.Open("default", cfg)
44 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b