cmd

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_FUZZY_DISTANCE = 2 // Maximum Levenshtein distance for fuzzy search. Higher values are more permissive
View Source
const VERSION = "0.1.1"

Variables

View Source
var (
	InfoLogger  *log.Logger
	ErrorLogger *log.Logger
)

Functions

func Execute

func Execute()

func GenerateCacheKey

func GenerateCacheKey(user string) ([32]byte, error)

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

func GetCachePath(cacheKey [32]byte) (string, error)

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

func GetStarredRepos(user string, cacheKey [32]byte) (bytes.Buffer, error)

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 Render

func Render(results pq.PriorityQueue, limit int, renderTarget io.Writer) error

func RenderJsonOutput added in v0.1.2

func RenderJsonOutput(results pq.PriorityQueue, limit int, renderTarget io.Writer) error

RenderJsonOutput renders the results in JSON format

func RenderLimit added in v0.1.2

func RenderLimit(resultsCount int, limit int) int

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

func RenderTable(results pq.PriorityQueue, limit int, renderTarget io.Writer) error
func Search(starredRepos bytes.Buffer, find string) (pq.PriorityQueue, error)

Find the search term in the starred repos Returns a priority queue with the results sorted by rank (the higher the rank, the more accurate the match)

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"`
}

Jump to

Keyboard shortcuts

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