vain

package module
v0.0.0-...-559cbd0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2016 License: BSD-3-Clause Imports: 22 Imported by: 0

README

vain

vaind is a vanity url server for use by the go tool.

installation

$ go get mcquay.me/vain/cmd/vaind

running server

$ VAIN_FROM=me@example.org vaind vain.db

Documentation

Overview

Package vain implements a vanity service for use by the the go tool.

The executable, cmd/vaind, is located in the respective subdirectory. vaind, a webserver for hosting go get vanity urls.

The go get command searches for the following header when searching for packages:

<meta name="go-import" content="import-prefix vcs repo-root">

this is simply a service for aggregating a collection of prefix, vcs, and repo-root tuples, and serving the appropriate header over http. For more information please refer to the documentation for the go tool found at https://golang.org/cmd/go/#hdr-Remote_import_paths

For instructions on how to use this service, build the daemon, run it, and visit the root url.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Valid

func Valid(p string, packages []Package) bool

Valid checks that p will not confuse the go tool if added to packages.

Types

type Email

type Email string

Email is a vain type for storing email addresses.

type Mail

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

Mail stores information required to use smtp.

func NewMail

func NewMail(from, host string, port int) (*Mail, error)

NewMail returns *Send struct to be able to send smtp or an error if it can't correctly parse the email address.

func (Mail) Send

func (e Mail) Send(to mail.Address, subject, msg string) error

Send sends a smtp email using the host and port in the Mail struct and returns an error if there was a problem sending the email.

type Mailer

type Mailer interface {
	Send(to mail.Address, subject, msg string) error
}

A Mailer is a type that knows how to send smtp mail.

type MemDB

type MemDB struct {
	Users      map[Email]User
	TokToEmail map[Token]Email

	Packages   map[path]Package
	Namespaces map[namespace]Email
	// contains filtered or unexported fields
}

MemDB implements an in-memory, and disk-backed database for a vain server.

func NewMemDB

func NewMemDB(p string) (*MemDB, error)

NewMemDB returns a functional MemDB.

func TestDB

func TestDB(t *testing.T) (*MemDB, func())

TestDB returns a populated MemDB in a temp location, as well as a function to call at cleanup time.

func (*MemDB) AddPackage

func (m *MemDB) AddPackage(p Package) error

AddPackage adds p into packages table.

func (*MemDB) Confirm

func (m *MemDB) Confirm(tok Token) (Token, error)

Confirm modifies the user with the given token. Used on register confirmation.

func (*MemDB) Forgot

func (m *MemDB) Forgot(e Email, window time.Duration) (Token, error)

Forgot is used fetch a user's token. It implements rudimentary rate limiting.

func (*MemDB) NSForToken

func (m *MemDB) NSForToken(ns namespace, tok Token) error

NSForToken creates an entry namespaces with a relation to the token.

func (*MemDB) Package

func (m *MemDB) Package(pth string) (Package, error)

Package fetches the package associated with path.

func (*MemDB) PackageExists

func (m *MemDB) PackageExists(pth path) bool

PackageExists tells if a package with path is in the database.

func (*MemDB) Pkgs

func (m *MemDB) Pkgs() []Package

Pkgs returns all packages from the database

func (*MemDB) Register

func (m *MemDB) Register(e Email) (Token, error)

Register adds email to the database, returning an error if there was one.

func (*MemDB) RemovePackage

func (m *MemDB) RemovePackage(pth path) error

RemovePackage removes package with given path

func (*MemDB) Sync

func (m *MemDB) Sync() error

Sync takes a lock, and flushes the data to disk.

type Package

type Package struct {
	//Vcs (version control system) supported: "hg", "git", "bzr", "svn"
	Vcs string `json:"vcs"`
	// Repo: the remote repository url
	Repo string `json:"repo"`

	Path string    `json:"path"`
	Ns   namespace `json:"-"`
}

Package stores the three pieces of information needed to create the meta tag. Two of these (Vcs and Repo) are stored explicitly, and the third is determined implicitly by the path POSTed to. For more information refer to the documentation for the go tool:

https://golang.org/cmd/go/#hdr-Remote_import_paths

func (Package) String

func (p Package) String() string

type Server

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

Server serves up the http.

func NewServer

func NewServer(sm *http.ServeMux, store Storer, m Mailer, static string, emailTimeout time.Duration, insecure bool) *Server

NewServer populates a server, adds the routes, and returns it for use.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

type Storer

type Storer interface {
	NSForToken(ns namespace, tok Token) error

	Package(path string) (Package, error)
	AddPackage(p Package) error
	RemovePackage(pth path) error
	PackageExists(pth path) bool
	Pkgs() []Package

	Register(e Email) (Token, error)
	Confirm(tok Token) (Token, error)
	Forgot(e Email, window time.Duration) (Token, error)
}

Storer defines the db interface.

type Token

type Token string

Token is a vain type for an api token.

func FreshToken

func FreshToken() Token

FreshToken returns a random token string.

type User

type User struct {
	Email Email

	Registered bool
	Requested  time.Time
	// contains filtered or unexported fields
}

User stores the information about a user including email used, their token, whether they have registerd and the requested timestamp

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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