gist

package module
v0.0.0-...-b3380e5 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2014 License: MIT Imports: 22 Imported by: 0

README

gist Build Status Coverage Status GoDoc Project status

This project is a mirror for hosting GitHub gist repositories.

Getting Started

Prerequisites

Before you start using the Gist application you'll need to create a new GitHub application. You can do this by going to your GitHub settings page, clicking on "Applications", and then creating a new application. You'll need to copy the token and secret that are generated and pass those into your application later.

Installing and Running

Simply go get the gist project:

$ go get github.com/benbjohnson/gist/...

Then run the gistd binary:

$ gistd -d ~/gist -key $GITHUB_API_TOKEN -secret $GITHUB_API_SECRET
Listening on http://localhost:40000

You can now visit http://localhost:40000 to view the application.

Documentation

Index

Constants

View Source
const (
	// DefaultFilename is the default file used if none is specified in the URL.
	DefaultFilename = "index.html"

	// DefaultEmbedHeight is the height returned from the oEmbed endpoint.
	DefaultEmbedHeight = 300

	// EmbedCacheAge is the number of seconds a consumer should cache an oEmbed.
	EmbedCacheAge = 0
)

Variables

This section is empty.

Functions

func ParsePath

func ParsePath(s string) (gistID, filename string, err error)

ParsePath extracts the gist id and filename from the path.

Types

type DB

type DB struct {
	*bolt.DB

	// GistPath to the root of the gist data.
	GistPath string

	// NewGitHubClient is the function used to return a new github client.
	NewGitHubClient func(string) GitHubClient
	// contains filtered or unexported fields
}

DB represents the application-level database.

func (*DB) GistFilePath

func (db *DB) GistFilePath(gistID, filename string) string

GistFilePath returns the path for a given gist file.

func (*DB) LoadGist

func (db *DB) LoadGist(userID int, gistID string) error

LoadGist retrieves the latest gist files from GitHub.

func (*DB) Open

func (db *DB) Open(path string, mode os.FileMode) error

Open opens and initializes the database.

func (*DB) Secret

func (db *DB) Secret() []byte

Secret returns the secure secret key.

func (*DB) Update

func (db *DB) Update(fn func(*Tx) error) error

Update executes a function in the context of a writable transaction.

func (*DB) View

func (db *DB) View(fn func(*Tx) error) error

View executes a function in the context of a read-only transaction.

type Gist

type Gist struct {
	ID          string      `json:"id"`
	UserID      int         `json:"userID"`
	Description string      `json:"description"`
	Public      bool        `json:"public"`
	URL         string      `json:"url"`
	Files       []*GistFile `json:"files"`
	CreatedAt   time.Time   `json:"createdAt"`
}

Gist represents a single GitHub gist.

type GistFile

type GistFile struct {
	Size     int    `json:"size"`
	Filename string `json:"filename"`
	RawURL   string `json:"rawURL"`
}

GistFile represents an individual file within a gist.

type GitHubClient

type GitHubClient interface {
	SetBaseURL(u string)
	User(username string) (*User, error)
	Gists(username string) ([]*Gist, error)
	Gist(id string) (*Gist, error)
}

GitHubClient is an interface for abstracting the GitHub API.

func NewGitHubClient

func NewGitHubClient(token string) GitHubClient

NewGitHubClient returns an instance of GitHubClient using a given access token.

type Handler

type Handler struct {
	Store  sessions.Store
	Logger *log.Logger

	// NewGitHubClient returns a new GitHub client.
	NewGitHubClient func(string) GitHubClient

	// ExchangeFunc processes a returned OAuth2 code into a token.
	// This function is used for testing.
	ExchangeFunc func(string) (*oauth.Token, error)
	// contains filtered or unexported fields
}

Handler represents the root HTTP handler for the application.

func NewHandler

func NewHandler(db *DB, token, secret string) *Handler

NewHandler returns a new instance of Handler.

func (*Handler) DB

func (h *Handler) DB() *DB

DB returns the database reference.

func (*Handler) HandleDashboard

func (h *Handler) HandleDashboard(w http.ResponseWriter, r *http.Request)

HandleDashboard serves the dashboard page.

func (*Handler) HandleGist

func (h *Handler) HandleGist(w http.ResponseWriter, r *http.Request)

HandleGist serves a single file for a gist. If the root is requested then the gist content is refreshed.

func (*Handler) HandleLogin

func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin redirects the user to GitHub OAuth2 authorization.

func (*Handler) HandleLoginCallback

func (h *Handler) HandleLoginCallback(w http.ResponseWriter, r *http.Request)

HandleLoginCallback receives the GitHub OAuth2 callback.

func (*Handler) HandleLogout

func (h *Handler) HandleLogout(w http.ResponseWriter, r *http.Request)

HandleLogout removes user authentication.

func (*Handler) HandleOEmbed

func (h *Handler) HandleOEmbed(w http.ResponseWriter, r *http.Request)

HandleOEmbed provides an oEmbed endpoint.

func (*Handler) HandleOEmbedJSON

func (h *Handler) HandleOEmbedJSON(w http.ResponseWriter, r *http.Request)

HandleOEmbedJSON provides an oEmbed endpoint.

func (*Handler) HandleRoot

func (h *Handler) HandleRoot(w http.ResponseWriter, r *http.Request)

HandleRoot serves the home page.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP dispatches incoming HTTP requests.

func (*Handler) Session

func (h *Handler) Session(r *http.Request) *Session

Session returns the current session.

type Session

type Session struct {
	*sessions.Session
}

Session represents an HTTP session.

func (*Session) Authenticated

func (s *Session) Authenticated() bool

Authenticated returns true if there is a user attached to the session.

func (*Session) UserID

func (s *Session) UserID() int

UserID returns the user id on the session.

type Tx

type Tx struct {
	*bolt.Tx
}

Tx represents an application-level transaction.

func (*Tx) GenerateSecretIfNotExists

func (tx *Tx) GenerateSecretIfNotExists() error

GenerateSecretIfNotExists generates a 64-byte secret key.

func (*Tx) Gist

func (tx *Tx) Gist(id string) (g *Gist, err error)

Gist retrieves a gist from the database by ID.

func (*Tx) GistsByUserID

func (tx *Tx) GistsByUserID(userID int) ([]*Gist, error)

GistsByUserID retrieves a list of gists owned by a user.

func (*Tx) SaveGist

func (tx *Tx) SaveGist(g *Gist) error

SaveGist stores a gist in the database.

func (*Tx) SaveUser

func (tx *Tx) SaveUser(u *User) error

SaveUser stores an user in the database.

func (*Tx) Secret

func (tx *Tx) Secret() []byte

Secret returns the 64-byte secret key.

func (*Tx) User

func (tx *Tx) User(id int) (u *User, err error)

User retrieves an user from the database by ID.

type User

type User struct {
	ID          int    `json:"id"`
	Username    string `json:"username"`
	AccessToken string `json:"accessToken"`
}

User represents a GitHub authorized user on the system.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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