Documentation ¶
Index ¶
- Constants
- func ParsePath(s string) (gistID, filename string, err error)
- type DB
- type Gist
- type GistFile
- type GitHubClient
- type Handler
- func (h *Handler) DB() *DB
- func (h *Handler) HandleDashboard(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleGist(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleLoginCallback(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleLogout(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleOEmbed(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleOEmbedJSON(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleRoot(w http.ResponseWriter, r *http.Request)
- func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *Handler) Session(r *http.Request) *Session
- type Session
- type Tx
- func (tx *Tx) GenerateSecretIfNotExists() error
- func (tx *Tx) Gist(id string) (g *Gist, err error)
- func (tx *Tx) GistsByUserID(userID int) ([]*Gist, error)
- func (tx *Tx) SaveGist(g *Gist) error
- func (tx *Tx) SaveUser(u *User) error
- func (tx *Tx) Secret() []byte
- func (tx *Tx) User(id int) (u *User, err error)
- type User
Constants ¶
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 ¶
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 ¶
GistFilePath returns the path for a given gist file.
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 ¶
NewHandler returns a new instance of Handler.
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.
type Session ¶
Session represents an HTTP session.
func (*Session) Authenticated ¶
Authenticated returns true if there is a user attached to the session.
type Tx ¶
Tx represents an application-level transaction.
func (*Tx) GenerateSecretIfNotExists ¶
GenerateSecretIfNotExists generates a 64-byte secret key.
func (*Tx) GistsByUserID ¶
GistsByUserID retrieves a list of gists owned by a user.