Search Gear #14 – Pseudo Constructors!

Changed the config twitter caller to a pseudo constructor thus

func NewTwitter(file string) (*twitter, error) {
tw := new(twitter)
 var parser toml.Parser
if _, err := ioutil.ReadFile(file); err != nil {
 tw.errors = errors.New(co.Lang("could not find the configuration file, you'll need to provide these setting for twitter to work"))
 } else {
 toml := parser.ParseFile(file)
tw.userKey = toml.GetString("twitter.user-key")
 tw.userSecret = toml.GetString("twitter.user-secret")
 tw.apiKey = toml.GetString("twitter.api-key", "26276391-gtihvXIuNXzCD4HTOjx8630O8IPq19m810TxkLMmd")
 tw.apiSecret = toml.GetString("twitter.api-secret", "bYkulR93l70elsjZysjjDpxQT69RVF2GIUcjoMIkrADoc")
 tw.users, _ = toml.GetValue("twitter.specific-users")
 tw.tags, _ = toml.GetValue("twitter.specific-tags")
 tw.errors = nil
 return tw, tw.errors

Called using

twitter, errors := NewTwitter(“myconfig”)

Test PASS woot!

I get happy very easily!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s