gists

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 12 Imported by: 0

README

Gists

Go Report Card PkgGoDev

A program to download all the user's gists from Github

Installation

Download the Git repository and install the executables

git clone git@github.com:/philhanna/gists
cd gists
go install cmd/download/gists_download.go
go install cmd/fs/gists_to_files.go

Create the configuration file:

  • On Linux/MacOS: $HOME/.config/gists/config.yaml
  • On Windows: %APPDATA%\gists\config.yaml with these parameters:
username: <your userID>
token: <a github token for this user>

See the Github documentation for details about how to create a Github access token.

Documentation

Index

Constants

View Source
const (
	PACKAGE_NAME     = "gists"
	CONFIG_FILE_NAME = "config.yaml"
)
View Source
const (
	URL_PREFIX       = "https://api.github.com/users"
	URL_SUFFIX       = "gists?per_page=10"
	LINK_HEADER_NAME = "Link"
	REL_NEXT_NAME    = "next"
)

Variables

This section is empty.

Functions

func AddHeaders

func AddHeaders(req *http.Request)

AddHeaders adds the required authorization headers to the HTTP request.

func CreateDatabase

func CreateDatabase(filename string) error

CreateDatabase reads gists from a channel and writes them to an SQLite3 database.

func FileExists

func FileExists(filename string) bool

FileExists returns true if the specified file exists

func GetConfigFileName

func GetConfigFileName() string

GetConfigFileName returns the name of the configuration file for this user.

func GetGistPages

func GetGistPages() chan string

GetGistPages downloads pages of gists from GitHub, sending them back as strings of JSON arrays.

func GetGists

func GetGists(jsonstr string) chan Gist

GetGists accepts a string containing a JSON array of gists and passes the individual gists back through a channel.

func LoadDatabase

func LoadDatabase(db *sql.DB, gist Gist) error

LoadDatabase writes a gist to the database

func MakeInitialURL

func MakeInitialURL() string

MakeInitialURL creates the URL for the first page of the gists

func MakeNextURL

func MakeNextURL(resp *http.Response) string

MakeNextURL finds the URL for the next page of the gists, or blank, if there are no more pages.

Types

type Configuration

type Configuration struct {
	Username string `yaml:"username"`
	Token    string `yaml:"token"`
}

Configuration contains the Github username and token

var Config *Configuration

func LoadConfig

func LoadConfig(filename string) (*Configuration, error)

LoadConfig reads the specified file and produces a configuration structure from it by parsing it as YAML.

type Gist

type Gist struct {
	ID          string              `json:"id,omitempty"`
	URL         string              `json:"url,omitempty"`
	Description string              `json:"description,omitempty"`
	CreatedAt   string              `json:"created_at"`
	Files       map[string]GistFile `json:"files,omitempty"`
}

Gist represents a single Github gist

func (Gist) String

func (g Gist) String() string

String creates a string representation of a gist.

type GistFile

type GistFile struct {
	Filename string `json:"filename,omitempty"`
	Type     string `json:"type,omitempty"`
	Language string `json:"language,omitempty"`
	RawURL   string `json:"raw_url,omitempty"`
	Size     int    `json:"size,omitempty"`
}

GistFile represents a single file in a gist, not including the content, which is pointed to by RawURL.

func NewGistFile

func NewGistFile(jsonstr string) (*GistFile, error)

NewGistFile creates a new GistFile structure from its JSON representation.

func (GistFile) GetContents

func (gf GistFile) GetContents() ([]byte, error)

GetContents retrieves the actual file contents from GitHub.

func (GistFile) String

func (gf GistFile) String() string

String returns a string representation of a GistFile.

type Link struct {
	URL string
	Rel string
}
func SplitLinks(s string) []Link

Directories

Path Synopsis
cmd
fs

Jump to

Keyboard shortcuts

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