Documentation
¶
Index ¶
- Constants
- Variables
- func Execute()
- func GenerateCacheKey(user string) ([32]byte, error)
- func GetCachePath(cacheKey [32]byte) (string, error)
- func GetStarredRepos(user string, cacheKey [32]byte) (bytes.Buffer, error)
- func Render(results pq.PriorityQueue, limit int, renderTarget io.Writer) error
- func RenderJsonOutput(results pq.PriorityQueue, limit int, renderTarget io.Writer) error
- func RenderLimit(resultsCount int, limit int) int
- func RenderTable(results pq.PriorityQueue, limit int, renderTarget io.Writer) error
- func Search(starredRepos bytes.Buffer, find string) (pq.PriorityQueue, error)
- type Repo
Constants ¶
const MAX_FUZZY_DISTANCE = 2 // Maximum Levenshtein distance for fuzzy search. Higher values are more permissive
const VERSION = "0.1.1"
Variables ¶
var ( InfoLogger *log.Logger ErrorLogger *log.Logger )
Functions ¶
func GenerateCacheKey ¶
Every API call to GitHub returns a header Link. This header contains the URL to the next & last pages of results. If we make a call to the API endpoint with 1 item per page, we will receive a Link header with the total number of pages equal to the total number of items. We can use this to generate a cache key that will be unique to the user and the number of items they have starred. When the user adds or removes an item, the cache key will change.
Caveat: if the user has starred an item then unstarred another item, the cache key will not change! This is an acceptable tradeoff for the simplicity of the implementation.
func GetCachePath ¶
GetCachePath returns the path to the cache file to use for storing starred repos. If the cache file path was not provided as input, it will create a new one. The cache file created uses the first 6 bytes of the cache key to generate a unique filename.
Example: <tmpdir>/stars_2d06a89b2687.json
func GetStarredRepos ¶
GetStarredRepos returns the starred repos for the given user. If the cache file exists and is not empty, it will read from the cache file. If the cache file does not exist or is empty, it will make an API call to GitHub to fetch the starred repos for the given user.
func RenderJsonOutput ¶ added in v0.1.2
RenderJsonOutput renders the results in JSON format
func RenderLimit ¶ added in v0.1.2
RenderLimit returns the limit to be used for rendering the results If the limit is -1, then return the total number of results Otherwise return the minimum of the limit and the total number of results
func RenderTable ¶ added in v0.1.2
Types ¶
type Repo ¶
type Repo struct { Name string `json:"name"` Full_name string `json:"full_name"` Private bool `json:"private"` Url string `json:"html_url"` Owner struct { Login string `json:"login"` Url string `json:"url"` } Description string `json:"description"` Fork bool `json:"fork"` Stars int `json:"stargazers_count"` Topics []string `json:"topics"` }