This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func GetAverageStarsPerRepo(repositoriesAPI RepositoriesAPI, username string) (float64, error) { | |
repos, err := repositoriesAPI.GetRepos(username) | |
if err != nil { | |
return 0, err | |
} | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package testable | |
import ( | |
"encoding/json" | |
"fmt" | |
"net/http" | |
) | |
type Repo struct { | |
StargazersCount int `json:"stargazers_count"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestGetAverageStarsPerRepo(t *testing.T) { | |
var tests = []struct { | |
username string | |
want float64 | |
}{ | |
{"octocat", 1480.375000}, | |
{"plutov", 15.566667}, | |
} | |
for _, tt := range tests { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Repo struct { | |
StargazersCount int `json:"stargazers_count"` | |
} | |
func GetAverageStarsPerRepo(username string) (float64, error) { | |
res, err := http.Get(fmt.Sprintf("https://api.github.com/users/%s/repos", username)) | |
if err != nil { | |
return 0, err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestStrInSlice(t *testing.T) { | |
var tests = []struct{ | |
slice []string | |
find string | |
want bool | |
}{ | |
{[]string{"a", "b"}, "c", false}, | |
{[]string{"a", "b"}, "a", true}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestStrInSlice(t *testing.T) { | |
got := StrInSlice([]string{"a", "b"}, "c") | |
if got == true { | |
t.Errorf("expecting false, got true") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func StrInSlice(slice []string, find string) bool { | |
for _, v := range slice { | |
if v == find { | |
return true | |
} | |
} | |
return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +build integration | |
package facest | |
import ( | |
"os" | |
"testing" | |
"github.com/stretchr/testify/assert" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *Client) sendRequest(req *http.Request, v interface{}) error { | |
req.Header.Set("Content-Type", "application/json; charset=utf-8") | |
req.Header.Set("Accept", "application/json; charset=utf-8") | |
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.apiKey)) | |
res, err := c.HTTPClient.Do(req) | |
if err != nil { | |
return err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *Client) GetFaces(ctx context.Context, options *FacesListOptions) (*FacesList, error) { | |
limit := 100 | |
page := 1 | |
if options != nil { | |
limit = options.Limit | |
page = options.Page | |
} | |
req, err := http.NewRequest("GET", fmt.Sprintf("%s/faces?limit=%d&page=%d", c.BaseURL, limit, page), nil) | |
if err != nil { |