Documentation ¶
Index ¶
- Constants
- Variables
- func NewCacheMiddleware(cache Cache, repo GithubRepository) *cacheMiddleware
- func NewHttpGithubRepository(appName string, cfg HttpConfig) *httpGithubRepository
- type Cache
- type CacheConfig
- type Contributor
- type GithubClient
- type GithubRepository
- type GithubRequest
- type GithubResponse
- type GithubResult
- type GithubTopRequest
- type HttpConfig
- type Location
- type LocationRanking
- type Ranking
- type RateLimitConfig
Constants ¶
const ( SortByRepositories = "repositories" SortByCommits = "commits" SortByLabels = "labels" Query = "location:%s" APIv1 = "v1" APIv2 = "v2" )
const (
// MaxPerPage max responses by page
MaxPerPage = 100
)
Variables ¶
var ( // ErrCacheMiss happens on entry not found in cache ErrCacheMiss = errors.New("entry not found in cache") )
var ErrMaxRetries = errors.New("max retries achieved")
ErrMaxRetries happens on max request achieved
Functions ¶
func NewCacheMiddleware ¶
func NewCacheMiddleware(cache Cache, repo GithubRepository) *cacheMiddleware
NewCacheMiddleware instantiates cached repository
func NewHttpGithubRepository ¶
func NewHttpGithubRepository(appName string, cfg HttpConfig) *httpGithubRepository
NewHttpGithubRepository instantiates http github repository
Types ¶
type Cache ¶
type Cache interface { // Add entry to cache Add(ctx context.Context, k string, v interface{}) error // Get entry from cache, puts Entry in top of LRU, so refresh expiration entry Get(ctx context.Context, k string) (interface{}, error) // Stop expiration worker Terminate() }
Cache defines a generic cache interface
type CacheConfig ¶
CacheConfig cache parameters configuration
func NewCacheConfig ¶
func NewCacheConfig(ttl, exp time.Duration) CacheConfig
NewCacheConfig instantiates config
type Contributor ¶
type Contributor struct { ID int64 `json:"id"` Name string `json:"name"` Url string `json:"url"` Company string `json:"company,omitempty"` Email string `json:"email,omitempty"` Bio string `json:"bio,omitempty"` }
Contributor models github contributor
type GithubClient ¶
type GithubClient struct {
// contains filtered or unexported fields
}
GithubClient builds a github http client
func NewGithubClient ¶
func NewGithubClient(appName string, cfg HttpConfig) *GithubClient
NewGithubClient instantiates github http client
func (*GithubClient) DoRequest ¶
func (r *GithubClient) DoRequest(ctx context.Context, req GithubTopRequest, page, size int) ([]*Contributor, error)
DoRequest fires http request
type GithubRepository ¶
type GithubRepository interface {
GetGithubTopContributors(ctx context.Context, req GithubTopRequest) ([]*Contributor, error)
}
GithubRepository defines github repository
type GithubRequest ¶
type GithubRequest struct { Query string Options *github.SearchOptions }
GithubRequest defines request
type GithubResponse ¶
type GithubResponse struct { Result *github.UsersSearchResult Response *github.Response }
GithubResponse defines response
type GithubResult ¶
type GithubResult struct {
// contains filtered or unexported fields
}
GithubResult defines github contributors top query result
type GithubTopRequest ¶
GithubResult defines github contributors top query result
type HttpConfig ¶
type HttpConfig struct { OauthToken string Timeout time.Duration Retries int RateLimitConfig RateLimitConfig }
HttpConfig instantiates an http config
type Location ¶
type Location struct { Name string `json:"name"` Score int `json:"score"` Index int `json:"index"` }
Location models searched locations
type LocationRanking ¶
type LocationRanking struct {
// contains filtered or unexported fields
}
LocationRanking defines top searched locations generic ranking
func NewLocationRanking ¶
func NewLocationRanking(r Ranking) *LocationRanking
NewLocationRanking wraps ranking persistence
func (*LocationRanking) GetTopSearchedLocations ¶
func (d *LocationRanking) GetTopSearchedLocations(ctx context.Context, size int) ([]*Location, error)
GetTopSearchedLocations returns ranking top with "size"
func (*LocationRanking) IncreaseCityScore ¶
func (d *LocationRanking) IncreaseCityScore(ctx context.Context, city string) error
IncreaseCityScore increase city score by 1
type Ranking ¶
type Ranking interface { IncreaseScore(ctx context.Context, city string) error Top(ctx context.Context, size int) ([]*Location, error) Len(ctx context.Context) (int64, error) }
Ranking defines a generic Ranking
type RateLimitConfig ¶
RateLimitConfig defines rate limiter config
func NewRateLimitConfig ¶
func NewRateLimitConfig(w time.Duration, l int) RateLimitConfig
NewRateLimitConfig creates rate limiter config