repository

package
v0.0.0-...-25100ba Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("repository not found")

ErrNotFound is returned when a Repository was not found

Functions

func GitHubHandler

func GitHubHandler(repositories Service, tmpl *template.Template, notfoundTmpl *template.Template) http.HandlerFunc

GitHubHandler renders and responds with a html page to a http request

Types

type GitHub

type GitHub struct {
	// contains filtered or unexported fields
}

GitHub makes API calls to GitHub

func NewGitHubClient

func NewGitHubClient(token string, apiCalls metrics.Histogram) (*GitHub, error)

NewGitHubClient initializes a new GitHub client from a token

func (*GitHub) Get

func (gh *GitHub) Get(ctx context.Context, urlPath string) (Repository, error)

Get a repository's data from its urlPath

type GoDoc

type GoDoc struct {
	// contains filtered or unexported fields
}

GoDoc scrapes godoc.org

func NewGoDoc

func NewGoDoc(apiCalls metrics.Histogram) (*GoDoc, error)

NewGoDoc initializes GoDoc with a http client

func (*GoDoc) Get

func (gd *GoDoc) Get(ctx context.Context, urlPath string) (*GoDocInfo, error)

Get godoc's repository data from a urlPath

type GoDocInfo

type GoDocInfo struct {
	Imports   int
	Importers int
	Updated   time.Time
}

GoDocInfo is the parsed meta information from a godoc.org page

type Homepage

type Homepage struct {
	Popular []string
	Latest  []string
	Random  []string
}

Homepage contains urls of repositories with different categories

type License

type License struct {
	Name string
}

License of a Repository

type Repository

type Repository struct {
	URL         string
	Description string
	Updated     time.Time

	CurrentVersion Version
	License        License
	Statistics     []Statistic
	Topics         []Topic
	Versions       []Version
}

Repository is a software repository containing Go code.

type Service

type Service interface {
	Get(ctx context.Context, url string) (Repository, error)
	Homepage(ctx context.Context) (Homepage, error)
}

Service is an interface which should implement the actual business logic for repositories.

func NewMetricService

func NewMetricService(s Service, calls metrics.Histogram) Service

NewMetricService creates Service which wraps its methods with metrics

func NewService

func NewService(repositories Storage, gh *GitHub, gd *GoDoc) Service

NewService creates a new Service implementation which works with a Storage.

type Statistic

type Statistic struct {
	Name  string
	Value int
	URL   string
}

Statistic of a Repository

type Storage

type Storage interface {
	Get(ctx context.Context, url string) (Repository, error)
	GetPopular(ctx context.Context, limit int) ([]string, error)
	GetLatest(ctx context.Context, limit int) ([]string, error)
	GetRandom(ctx context.Context, limit int) ([]string, error)
	Exists(ctx context.Context, url string) (bool, error)
	Create(ctx context.Context, repo Repository) error
}

Storage is an interface which implementation should actually store and retrieve repositories.

func NewPostgresStorage

func NewPostgresStorage(db *sql.DB) Storage

NewPostgresStorage returns a Storage implementation using Postgres.

type Topic

type Topic struct{}

Topic describing a Repository

type Version

type Version struct {
	Name      string
	Published time.Time
}

Version a Repository was tagged with

Jump to

Keyboard shortcuts

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