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

Side by Side Diff: environs/open.go

Issue 6215045: environs: add NewEnviron(kind, config) (Closed)
Patch Set: environs: add NewEnviron(kind, config) Created 5 years, 8 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:
View unified diff | Download patch
OLDNEW
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
11 if name == "" { 10 if name == "" {
12 return nil, fmt.Errorf("no default environment found") 11 return nil, fmt.Errorf("no default environment found")
13 } 12 }
14 } 13 }
15 e, ok := envs.environs[name] 14 e, ok := envs.environs[name]
16 if !ok { 15 if !ok {
17 return nil, fmt.Errorf("unknown environment %q", name) 16 return nil, fmt.Errorf("unknown environment %q", name)
18 } 17 }
19 if e.err != nil { 18 if e.err != nil {
20 return nil, e.err 19 return nil, e.err
21 } 20 }
22 env, err := providers[e.kind].Open(name, e.config) 21 env, err := providers[e.kind].Open(name, e.config)
23 if err != nil { 22 if err != nil {
24 return nil, fmt.Errorf("cannot initialize environment %q: %v", n ame, err) 23 return nil, fmt.Errorf("cannot initialize environment %q: %v", n ame, err)
25 } 24 }
26 25
27 return env, nil 26 return env, nil
28 } 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.Check(config)
rog 2012/05/15 08:59:30 If Environs.Check must always accept a map[string]
niemeyer 2012/05/15 21:03:14 I like part of your idea, but this specific bit do
dfc 2012/05/15 23:16:01 It won't work, environProvider.Check() expects a m
37 if err != nil {
38 return nil, fmt.Errorf("error validating environment: %v", err)
39 }
40 // TODO(dfc) remove the requirement for an environment to know it's name , it's
41 // type should be sufficient.
42 return p.Open("default", cfg)
43 }
OLDNEW
« environs/interface.go ('K') | « environs/interface.go ('k') | environs/open_test.go » ('j') | no next file with comments »

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