provider

package
v0.0.0-...-3c22c5d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SortByRepositories = "repositories"
	SortByCommits      = "commits"
	SortByLabels       = "labels"
	Query              = "location:%s"
	APIv1              = "v1"
	APIv2              = "v2"
)
View Source
const (
	// MaxPerPage max responses by page
	MaxPerPage = 100
)

Variables

View Source
var (
	// ErrCacheMiss happens on entry not found in cache
	ErrCacheMiss = errors.New("entry not found in cache")
)
View Source
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

type CacheConfig struct {
	Ttl                 time.Duration
	ExpirationFrequency time.Duration
}

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

type GithubTopRequest struct {
	City    string
	Size    int
	Version string
	Sort    string
}

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

type RateLimitConfig struct {
	RateLimitWindow time.Duration
	RateLimitMaxReq int
}

RateLimitConfig defines rate limiter config

func NewRateLimitConfig

func NewRateLimitConfig(w time.Duration, l int) RateLimitConfig

NewRateLimitConfig creates rate limiter config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL