Use Credentials struct for NewClient

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2021-01-24 22:51:27 -05:00
parent 78dc97a8d5
commit 6d615771cb
6 changed files with 34 additions and 52 deletions
+5 -5
View File
@@ -46,8 +46,8 @@ package main
import "github.com/vartanbeno/go-reddit/reddit"
func main() {
withCredentials := reddit.WithCredentials("id", "secret", "username", "password")
client, _ := reddit.NewClient(withCredentials)
credentials := reddit.Credentials{ID: "id", Secret: "secret", Username: "username", Password: "password"}
client, _ := reddit.NewClient(credentials)
}
```
@@ -55,7 +55,7 @@ You can pass in a number of options to `NewClient` to further configure the clie
```go
httpClient := &http.Client{Timeout: time.Second * 30}
client, _ := reddit.NewClient(withCredentials, reddit.WithHTTPClient(httpClient))
client, _ := reddit.NewClient(credentials, reddit.WithHTTPClient(httpClient))
```
### Read-Only Mode
@@ -69,10 +69,10 @@ client, _ := reddit.NewReadonlyClient()
## Examples
<details>
<summary>Configure the client from environment variables.</summary>
<summary>Configure the client from environment variables. When using this option, it's ok to pass an empty struct for the credentials.</summary>
```go
client, _ := reddit.NewClient(reddit.FromEnv)
client, _ := reddit.NewClient(reddit.Credentials{}, reddit.FromEnv)
```
</details>