auth
102:267483f168b5 Browse Files
Require config.Init in Context, add comment. Add comment to config.Init explaining what it is, to make golint happy. Create an ErrConfigNotInitialized error to use when a Config object is used to create a Context before it is initialized. Check for Config initialization in NewContext and throw ErrConfigNotInitialized if the Config hasn't been initialized.
1.1 --- a/config.go Sun Dec 14 16:23:10 2014 -0500 1.2 +++ b/config.go Sun Dec 14 16:49:34 2014 -0500 1.3 @@ -9,6 +9,8 @@ 1.4 var ( 1.5 // ErrInvalidLoginURI is returned when a Context is instantiated with a Config object that specifies a LoginURI that can't be parsed as a URL. 1.6 ErrInvalidLoginURI = errors.New("invalid login URI") 1.7 + // ErrConfigNotInitialized is returned when a Context is instantiated with a Config object that hasn't had its Init function called. 1.8 + ErrConfigNotInitialized = errors.New("config not initialized") 1.9 ) 1.10 1.11 // Config holds the configuration values necessary to run a server. A Config 1.12 @@ -24,6 +26,8 @@ 1.13 iterations int 1.14 } 1.15 1.16 +// Init is a function that preps the Config object to be used for Context creation, setting variables 1.17 +// that are determined at the beginning of program execution. 1.18 func (c *Config) Init() error { 1.19 scheme, ok := passphraseSchemes[CurPassphraseScheme] 1.20 if !ok {
2.1 --- a/context.go Sun Dec 14 16:23:10 2014 -0500 2.2 +++ b/context.go Sun Dec 14 16:49:34 2014 -0500 2.3 @@ -27,6 +27,9 @@ 2.4 // NewContext takes a Config instance and uses it to bootstrap a Context 2.5 // using the information provided in the Config variable. 2.6 func NewContext(config Config) (Context, error) { 2.7 + if config.iterations == 0 { 2.8 + return Context{}, ErrConfigNotInitialized 2.9 + } 2.10 context := Context{ 2.11 clients: config.ClientStore, 2.12 authCodes: config.AuthCodeStore,