{"action":"created","comment":{"url":"https://api.github.com/repos/telenordigital/lassie-go/pulls/comments/149976861","pull_request_review_id":75452485,"id":149976861,"diff_hunk":"@@ -0,0 +1,156 @@\n+package lassie\n+\n+import (\n+\t\"bufio\"\n+\t\"bytes\"\n+\t\"io/ioutil\"\n+\t\"os\"\n+\t\"os/user\"\n+\t\"path/filepath\"\n+\t\"strings\"\n+)\n+\n+// ClientConfig is a client configuration for Lassie-go\n+type ClientConfig interface {\n+\t// Address returns the address to use\n+\tAddress() string\n+\t// Token returns the token to use\n+\tToken() string\n+}\n+\n+// NewWithConfig creates a new client with the provided configuration\n+func NewWithConfig(config ClientConfig) (*Client, error) {\n+\treturn NewWithAddr(config.Address(), config.Token())\n+}\n+\n+// EnvironmentConfig gets its configuration from environment variables\n+type EnvironmentConfig struct {\n+}\n+\n+// NewEnvironmentConfig creates a new EnvironmentConfig\n+func NewEnvironmentConfig() *EnvironmentConfig {\n+\treturn &EnvironmentConfig{}\n+}\n+\n+// Address tries to retrieve the endpoint address (ie https://api.lora.telenor.io)\n+// from the environment variable LASSIE_ADDRESS. If is empty it will return the\n+// default.\n+func (e *EnvironmentConfig) Address() string {\n+\tendpoint := os.Getenv(\"LASSIE_ADDRESS\")\n+\tif endpoint == \"\" {\n+\t\treturn DefaultAddr\n+\t}\n+\treturn endpoint\n+}\n+\n+// Token returns the token from the environment variable LASSIE_TOKEN\n+func (e *EnvironmentConfig) Token() string {\n+\treturn os.Getenv(\"LASSIE_TOKEN\")\n+}\n+\n+// UserConfig gets its configuration from a file named ~/.lassie\n+//\n+// The configuration format is quite simple with \"key=value\" entries on each\n+// line. Only two parameters are supported -- \"Address\" and \"Token\". The Address\n+// parameter is optional.\n+//\n+// Note: This isn't tested on Windows.\n+type UserConfig struct {\n+\tvalues map[string]string\n+}\n+\n+// NewUserConfig creates a new UserConfig\n+func NewUserConfig() *UserConfig {\n+\treturn &UserConfig{}\n+}\n+\n+const (\n+\taddressKey = \"address\"\n+\ttokenKey   = \"token\"\n+)\n+\n+func (u *UserConfig) configFile() string {\n+\tusr, err := user.Current()\n+\tif err != nil {\n+\t\treturn \"\"\n+\t}\n+\treturn filepath.Join(usr.HomeDir, \".lassie\")\n+}\n+\n+// readConfig populates the values map with two elements -- \"token\" and\n+// \"address\"\n+func (u *UserConfig) readConfig(filename string) map[string]string {\n+\tif u.values == nil {\n+\t\tu.values = make(map[string]string)\n+\t\tu.values[addressKey] = DefaultAddr\n+\t\tu.values[tokenKey] = \"\"\n+\n+\t\tbuf, err := ioutil.ReadFile(filename)\n+\t\tif err != nil {\n+\t\t\treturn u.values\n+\t\t}\n+\t\tscanner := bufio.NewScanner(bytes.NewReader(buf))\n+\t\tscanner.Split(bufio.ScanLines)\n+\t\tfor scanner.Scan() {\n+\t\t\twords := strings.Split(scanner.Text(), \"=\")\n+\t\t\tif len(words) == 1 {\n+\t\t\t\tcontinue\n+\t\t\t}\n+\t\t\tswitch strings.ToLower(strings.TrimSpace(words[0])) {\n+\t\t\tcase addressKey:\n+\t\t\t\tu.values[addressKey] = strings.TrimSpace(words[1])\n+\t\t\tcase tokenKey:\n+\t\t\t\tu.values[tokenKey] = strings.TrimSpace(words[1])\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn u.values\n+}\n+\n+// Address reads the configuration file and checks if the file has the field\n+// \"address\". If the field isn't found it will use the default address. If the\n+// file is missing it will use the defaults\n+func (u *UserConfig) Address() string {\n+\tu.readConfig(u.configFile())","path":"config.go","position":114,"original_position":114,"commit_id":"0d08fc1fdded1cbbe4f27e4529c43eab42bf5bbb","original_commit_id":"0d08fc1fdded1cbbe4f27e4529c43eab42bf5bbb","user":{"login":"gordonklaus","id":1638352,"avatar_url":"https://avatars2.githubusercontent.com/u/1638352?v=4","gravatar_id":"","url":"https://api.github.com/users/gordonklaus","html_url":"https://github.com/gordonklaus","followers_url":"https://api.github.com/users/gordonklaus/followers","following_url":"https://api.github.com/users/gordonklaus/following{/other_user}","gists_url":"https://api.github.com/users/gordonklaus/gists{/gist_id}","starred_url":"https://api.github.com/users/gordonklaus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gordonklaus/subscriptions","organizations_url":"https://api.github.com/users/gordonklaus/orgs","repos_url":"https://api.github.com/users/gordonklaus/repos","events_url":"https://api.github.com/users/gordonklaus/events{/privacy}","received_events_url":"https://api.github.com/users/gordonklaus/received_events","type":"User","site_admin":false},"body":"Wouldn't it make more sense to read the config file in NewUserConfig?  That is what I would expect to happen.  And it would simplify the code.","created_at":"2017-11-09T14:32:27Z","updated_at":"2017-11-09T14:51:26Z","html_url":"https://github.com/telenordigital/lassie-go/pull/3#discussion_r149976861","pull_request_url":"https://api.github.com/repos/telenordigital/lassie-go/pulls/3","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/telenordigital/lassie-go/pulls/comments/149976861"},"html":{"href":"https://github.com/telenordigital/lassie-go/pull/3#discussion_r149976861"},"pull_request":{"href":"https://api.github.com/repos/telenordigital/lassie-go/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/telenordigital/lassie-go/pulls/3","id":151399962,"html_url":"https://github.com/telenordigital/lassie-go/pull/3","diff_url":"https://github.com/telenordigital/lassie-go/pull/3.diff","patch_url":"https://github.com/telenordigital/lassie-go/pull/3.patch","issue_url":"https://api.github.com/repos/telenordigital/lassie-go/issues/3","number":3,"state":"open","locked":false,"title":"Even more ways to configure the client","user":{"login":"stalehd","id":1106984,"avatar_url":"https://avatars0.githubusercontent.com/u/1106984?v=4","gravatar_id":"","url":"https://api.github.com/users/stalehd","html_url":"https://github.com/stalehd","followers_url":"https://api.github.com/users/stalehd/followers","following_url":"https://api.github.com/users/stalehd/following{/other_user}","gists_url":"https://api.github.com/users/stalehd/gists{/gist_id}","starred_url":"https://api.github.com/users/stalehd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stalehd/subscriptions","organizations_url":"https://api.github.com/users/stalehd/orgs","repos_url":"https://api.github.com/users/stalehd/repos","events_url":"https://api.github.com/users/stalehd/events{/privacy}","received_events_url":"https://api.github.com/users/stalehd/received_events","type":"User","site_admin":false},"body":"Add two convenience classes for configuration -- one that uses the environment and one that uses a configuration file in the user's home directory.\r\n\r\nThe latter is mainly for development.","created_at":"2017-11-08T14:40:01Z","updated_at":"2017-11-09T14:51:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3ea58d09226ca96ab71cbb1781b36e6894f30941","assignee":null,"assignees":[],"requested_reviewers":[{"login":"borud","id":1595,"avatar_url":"https://avatars0.githubusercontent.com/u/1595?v=4","gravatar_id":"","url":"https://api.github.com/users/borud","html_url":"https://github.com/borud","followers_url":"https://api.github.com/users/borud/followers","following_url":"https://api.github.com/users/borud/following{/other_user}","gists_url":"https://api.github.com/users/borud/gists{/gist_id}","starred_url":"https://api.github.com/users/borud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borud/subscriptions","organizations_url":"https://api.github.com/users/borud/orgs","repos_url":"https://api.github.com/users/borud/repos","events_url":"https://api.github.com/users/borud/events{/privacy}","received_events_url":"https://api.github.com/users/borud/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/telenordigital/lassie-go/pulls/3/commits","review_comments_url":"https://api.github.com/repos/telenordigital/lassie-go/pulls/3/comments","review_comment_url":"https://api.github.com/repos/telenordigital/lassie-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/telenordigital/lassie-go/issues/3/comments","statuses_url":"https://api.github.com/repos/telenordigital/lassie-go/statuses/0d08fc1fdded1cbbe4f27e4529c43eab42bf5bbb","head":{"label":"stalehd:save_params","ref":"save_params","sha":"0d08fc1fdded1cbbe4f27e4529c43eab42bf5bbb","user":{"login":"stalehd","id":1106984,"avatar_url":"https://avatars0.githubusercontent.com/u/1106984?v=4","gravatar_id":"","url":"https://api.github.com/users/stalehd","html_url":"https://github.com/stalehd","followers_url":"https://api.github.com/users/stalehd/followers","following_url":"https://api.github.com/users/stalehd/following{/other_user}","gists_url":"https://api.github.com/users/stalehd/gists{/gist_id}","starred_url":"https://api.github.com/users/stalehd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stalehd/subscriptions","organizations_url":"https://api.github.com/users/stalehd/orgs","repos_url":"https://api.github.com/users/stalehd/repos","events_url":"https://api.github.com/users/stalehd/events{/privacy}","received_events_url":"https://api.github.com/users/stalehd/received_events","type":"User","site_admin":false},"repo":{"id":109971272,"name":"lassie-go","full_name":"stalehd/lassie-go","owner":{"login":"stalehd","id":1106984,"avatar_url":"https://avatars0.githubusercontent.com/u/1106984?v=4","gravatar_id":"","url":"https://api.github.com/users/stalehd","html_url":"https://github.com/stalehd","followers_url":"https://api.github.com/users/stalehd/followers","following_url":"https://api.github.com/users/stalehd/following{/other_user}","gists_url":"https://api.github.com/users/stalehd/gists{/gist_id}","starred_url":"https://api.github.com/users/stalehd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stalehd/subscriptions","organizations_url":"https://api.github.com/users/stalehd/orgs","repos_url":"https://api.github.com/users/stalehd/repos","events_url":"https://api.github.com/users/stalehd/events{/privacy}","received_events_url":"https://api.github.com/users/stalehd/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stalehd/lassie-go","description":"LoRa as a Service Client for Go","fork":true,"url":"https://api.github.com/repos/stalehd/lassie-go","forks_url":"https://api.github.com/repos/stalehd/lassie-go/forks","keys_url":"https://api.github.com/repos/stalehd/lassie-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stalehd/lassie-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stalehd/lassie-go/teams","hooks_url":"https://api.github.com/repos/stalehd/lassie-go/hooks","issue_events_url":"https://api.github.com/repos/stalehd/lassie-go/issues/events{/number}","events_url":"https://api.github.com/repos/stalehd/lassie-go/events","assignees_url":"https://api.github.com/repos/stalehd/lassie-go/assignees{/user}","branches_url":"https://api.github.com/repos/stalehd/lassie-go/branches{/branch}","tags_url":"https://api.github.com/repos/stalehd/lassie-go/tags","blobs_url":"https://api.github.com/repos/stalehd/lassie-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stalehd/lassie-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stalehd/lassie-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/stalehd/lassie-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stalehd/lassie-go/statuses/{sha}","languages_url":"https://api.github.com/repos/stalehd/lassie-go/languages","stargazers_url":"https://api.github.com/repos/stalehd/lassie-go/stargazers","contributors_url":"https://api.github.com/repos/stalehd/lassie-go/contributors","subscribers_url":"https://api.github.com/repos/stalehd/lassie-go/subscribers","subscription_url":"https://api.github.com/repos/stalehd/lassie-go/subscription","commits_url":"https://api.github.com/repos/stalehd/lassie-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/stalehd/lassie-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/stalehd/lassie-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/stalehd/lassie-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/stalehd/lassie-go/contents/{+path}","compare_url":"https://api.github.com/repos/stalehd/lassie-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stalehd/lassie-go/merges","archive_url":"https://api.github.com/repos/stalehd/lassie-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stalehd/lassie-go/downloads","issues_url":"https://api.github.com/repos/stalehd/lassie-go/issues{/number}","pulls_url":"https://api.github.com/repos/stalehd/lassie-go/pulls{/number}","milestones_url":"https://api.github.com/repos/stalehd/lassie-go/milestones{/number}","notifications_url":"https://api.github.com/repos/stalehd/lassie-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stalehd/lassie-go/labels{/name}","releases_url":"https://api.github.com/repos/stalehd/lassie-go/releases{/id}","deployments_url":"https://api.github.com/repos/stalehd/lassie-go/deployments","created_at":"2017-11-08T12:11:36Z","updated_at":"2017-11-08T12:11:38Z","pushed_at":"2017-11-08T15:25:42Z","git_url":"git://github.com/stalehd/lassie-go.git","ssh_url":"git@github.com:stalehd/lassie-go.git","clone_url":"https://github.com/stalehd/lassie-go.git","svn_url":"https://github.com/stalehd/lassie-go","homepage":null,"size":14,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"telenordigital:master","ref":"master","sha":"f9ac94d0ca8c24200a8b241818d10dcc164c58d4","user":{"login":"telenordigital","id":14310842,"avatar_url":"https://avatars0.githubusercontent.com/u/14310842?v=4","gravatar_id":"","url":"https://api.github.com/users/telenordigital","html_url":"https://github.com/telenordigital","followers_url":"https://api.github.com/users/telenordigital/followers","following_url":"https://api.github.com/users/telenordigital/following{/other_user}","gists_url":"https://api.github.com/users/telenordigital/gists{/gist_id}","starred_url":"https://api.github.com/users/telenordigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telenordigital/subscriptions","organizations_url":"https://api.github.com/users/telenordigital/orgs","repos_url":"https://api.github.com/users/telenordigital/repos","events_url":"https://api.github.com/users/telenordigital/events{/privacy}","received_events_url":"https://api.github.com/users/telenordigital/received_events","type":"Organization","site_admin":false},"repo":{"id":108915389,"name":"lassie-go","full_name":"telenordigital/lassie-go","owner":{"login":"telenordigital","id":14310842,"avatar_url":"https://avatars0.githubusercontent.com/u/14310842?v=4","gravatar_id":"","url":"https://api.github.com/users/telenordigital","html_url":"https://github.com/telenordigital","followers_url":"https://api.github.com/users/telenordigital/followers","following_url":"https://api.github.com/users/telenordigital/following{/other_user}","gists_url":"https://api.github.com/users/telenordigital/gists{/gist_id}","starred_url":"https://api.github.com/users/telenordigital/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telenordigital/subscriptions","organizations_url":"https://api.github.com/users/telenordigital/orgs","repos_url":"https://api.github.com/users/telenordigital/repos","events_url":"https://api.github.com/users/telenordigital/events{/privacy}","received_events_url":"https://api.github.com/users/telenordigital/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/telenordigital/lassie-go","description":"LoRa as a Service Client for Go","fork":false,"url":"https://api.github.com/repos/telenordigital/lassie-go","forks_url":"https://api.github.com/repos/telenordigital/lassie-go/forks","keys_url":"https://api.github.com/repos/telenordigital/lassie-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telenordigital/lassie-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telenordigital/lassie-go/teams","hooks_url":"https://api.github.com/repos/telenordigital/lassie-go/hooks","issue_events_url":"https://api.github.com/repos/telenordigital/lassie-go/issues/events{/number}","events_url":"https://api.github.com/repos/telenordigital/lassie-go/events","assignees_url":"https://api.github.com/repos/telenordigital/lassie-go/assignees{/user}","branches_url":"https://api.github.com/repos/telenordigital/lassie-go/branches{/branch}","tags_url":"https://api.github.com/repos/telenordigital/lassie-go/tags","blobs_url":"https://api.github.com/repos/telenordigital/lassie-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telenordigital/lassie-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telenordigital/lassie-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/telenordigital/lassie-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telenordigital/lassie-go/statuses/{sha}","languages_url":"https://api.github.com/repos/telenordigital/lassie-go/languages","stargazers_url":"https://api.github.com/repos/telenordigital/lassie-go/stargazers","contributors_url":"https://api.github.com/repos/telenordigital/lassie-go/contributors","subscribers_url":"https://api.github.com/repos/telenordigital/lassie-go/subscribers","subscription_url":"https://api.github.com/repos/telenordigital/lassie-go/subscription","commits_url":"https://api.github.com/repos/telenordigital/lassie-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/telenordigital/lassie-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/telenordigital/lassie-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/telenordigital/lassie-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/telenordigital/lassie-go/contents/{+path}","compare_url":"https://api.github.com/repos/telenordigital/lassie-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telenordigital/lassie-go/merges","archive_url":"https://api.github.com/repos/telenordigital/lassie-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telenordigital/lassie-go/downloads","issues_url":"https://api.github.com/repos/telenordigital/lassie-go/issues{/number}","pulls_url":"https://api.github.com/repos/telenordigital/lassie-go/pulls{/number}","milestones_url":"https://api.github.com/repos/telenordigital/lassie-go/milestones{/number}","notifications_url":"https://api.github.com/repos/telenordigital/lassie-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telenordigital/lassie-go/labels{/name}","releases_url":"https://api.github.com/repos/telenordigital/lassie-go/releases{/id}","deployments_url":"https://api.github.com/repos/telenordigital/lassie-go/deployments","created_at":"2017-10-30T22:28:20Z","updated_at":"2017-10-30T22:33:05Z","pushed_at":"2017-11-08T15:25:43Z","git_url":"git://github.com/telenordigital/lassie-go.git","ssh_url":"git@github.com:telenordigital/lassie-go.git","clone_url":"https://github.com/telenordigital/lassie-go.git","svn_url":"https://github.com/telenordigital/lassie-go","homepage":null,"size":9,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/telenordigital/lassie-go/pulls/3"},"html":{"href":"https://github.com/telenordigital/lassie-go/pull/3"},"issue":{"href":"https://api.github.com/repos/telenordigital/lassie-go/issues/3"},"comments":{"href":"https://api.github.com/repos/telenordigital/lassie-go/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/telenordigital/lassie-go/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/telenordigital/lassie-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/telenordigital/lassie-go/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/telenordigital/lassie-go/statuses/0d08fc1fdded1cbbe4f27e4529c43eab42bf5bbb"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"gordonklaus"}}