gopaste

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

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

Go to latest
Published: Jan 14, 2019 License: AGPL-3.0 Imports: 20 Imported by: 0

README

Gopaste

Synopsis

go get github.com/wisnij/gopaste/gopasted
cd $GOPATH/src/github.com/wisnij/gopaste
$GOPATH/bin/gopasted [--source=gopaste.sqlite] [--port=80]

Description

Gopaste is a simple pastebin written in Go.

Features
  • Syntax highlighting (courtesy of highlight.js)
  • Paste annotation and diffs
  • Private pastes
  • IRC integration via Hubot
Possible future features
  • Full text search
  • Per-line comments
  • RESTful API

Author

Copyright (C) 2014 Jim Wisniewski <wisnij@gmail.com>. Released under GNU AGPLv3 (see LICENSE for full legalese).

Basic design inspired by/shamelessly stolen from lpaste.

Documentation

Index

Constants

View Source
const (
	DefaultDriver   = "sqlite3"
	DefaultDatabase = "gopaste.sqlite"
	DefaultPort     = 80
)
View Source
const (
	InvalidPasteId = -1
	TimeFormat     = "2006-01-02 15:04:05 -07:00"
)
View Source
const (
	Minute = 60
	Hour   = 60 * Minute
	Day    = 24 * Hour
	Week   = 7 * Day
	Month  = 30 * Day
	Year   = 365 * Day
)

Variables

View Source
var LanguageNames = map[string]string{}/* 110 elements not displayed */

LanguageNames maps language identifers to the human-readable names of the languages supported by highlightjs.

View Source
var LanguageNamesSorted = []languageName{}

LanguageNamesSorted is a list of known languages, sorted by name.

Functions

func AnnotationOrdinal

func AnnotationOrdinal(dbh *sql.DB, pasteId int64) (int, error)

AnnotationOrdinal returns N such that the paste is the Nth annotation of its parent.

func InsertPaste

func InsertPaste(dbh *sql.DB, paste *Paste) (int64, error)

Types

type ActionFunc

type ActionFunc func(*Server, *Query) error

type AnyMap

type AnyMap map[string]interface{}

type BrowseOpts

type BrowseOpts struct {
	Page     int
	PageSize int
	Search   map[string]string
}

func NewBrowseOpts

func NewBrowseOpts() *BrowseOpts

func (*BrowseOpts) Nearby

func (o *BrowseOpts) Nearby(window int, max int) (pages []int)

func (*BrowseOpts) NewPage

func (o *BrowseOpts) NewPage(page int) *BrowseOpts

func (*BrowseOpts) Next

func (o *BrowseOpts) Next() *BrowseOpts

func (*BrowseOpts) Parse

func (o *BrowseOpts) Parse(args []string) error

func (*BrowseOpts) Prev

func (o *BrowseOpts) Prev() *BrowseOpts

func (*BrowseOpts) String

func (o *BrowseOpts) String() string

type Config

type Config struct {
	DbDriver     string
	DbSource     string
	Port         uint
	ExternalHost string
	HubotHost    string
}

func ParseConfig

func ParseConfig() *Config

ParseConfig creates a new Config object by reading the command-line arguments.

type HttpError

type HttpError struct {
	Message string
	Code    int
}

func (HttpError) Error

func (e HttpError) Error() string

type LineNumber

type LineNumber struct {
	Num    int
	Anchor string
}

type Paste

type Paste struct {
	Id            int64          `sql:"id"`
	Title         sql.NullString `sql:"title"`
	Content       string         `sql:"content"`
	Author        sql.NullString `sql:"author"`
	Language      sql.NullString `sql:"language"`
	Channel       sql.NullString `sql:"channel"`
	Annotates     sql.NullInt64  `sql:"annotates"`
	Private       bool           `sql:"private"`
	Created       int64          `sql:"created"`
	AnnotationNum int            `sql:"-"`
}

Paste represents an individual paste.

func GetAnnotations

func GetAnnotations(dbh *sql.DB, pasteId int64) ([]*Paste, error)

GetAnnotations fetches all annotations of the paste with the given ID.

func GetPaste

func GetPaste(dbh *sql.DB, pasteId int64) (*Paste, error)

GetPaste fetches a single paste from its ID.

func NewPaste

func NewPaste(v url.Values) *Paste

NewPaste creates a new paste from a submitted web form.

func (Paste) AuthorDef

func (p Paste) AuthorDef() string

AuthorDef returns the paste author if set, or "anonymous" otherwise.

func (Paste) ChannelDef

func (p Paste) ChannelDef() string

ChannelDef returns the paste channel if set, or the empty string otherwise.

func (Paste) CreatedDisplay

func (p Paste) CreatedDisplay() string

CreatedDisplay returns the paste creation date in a human-readable format.

func (Paste) CreatedRel

func (p Paste) CreatedRel() string

CreatedRel returns a string describing how long ago the paste was created, in a human-friendly format (e.g. "3 days ago").

func (Paste) CreatedTime

func (p Paste) CreatedTime() time.Time

CreatedTime returns the paste's creation time as a time.Time object.

func (Paste) LanguageDef

func (p Paste) LanguageDef() string

LanguageDef returns the full name of the paste language if set, or "plain text" otherwise.

func (Paste) LineNumbers

func (p Paste) LineNumbers() (ns []LineNumber)

LineNumbers returns a list of LineNumber objects for a paste.

func (Paste) ReplyTitle

func (p Paste) ReplyTitle() string

ReplyTitle returns the paste title prefixed with "Re:" if it doesn't already begin that way.

func (Paste) RootId

func (p Paste) RootId() int64

RootId returns the ID of the paste this one annotates, or this paste's ID if this is a top-level paste.

func (Paste) TitleDef

func (p Paste) TitleDef() string

TitleDef returns the paste title if set, or "untitled" otherwise.

type PasteData

type PasteData struct {
	Paste       *Paste
	Annotations []*Paste
}

PasteData represents a paste and all of its annotations.

func GetPasteData

func GetPasteData(dbh *sql.DB, pasteId int64) (*PasteData, error)

GetPasteData fetches a paste and its annotations from the given paste ID.

func (PasteData) AnnotationsView

func (d PasteData) AnnotationsView() (view []PasteView)

func (PasteData) PasteView

func (d PasteData) PasteView() *PasteView

type PastePage

type PastePage struct {
	Total  int
	Start  int
	End    int
	Pastes []*PasteData
}

func TopLevelPastes

func TopLevelPastes(dbh *sql.DB, opts *BrowseOpts) (*PastePage, error)

TopLevelPastes fetches the paste IDs for all pastes which are not private or annotations

func (*PastePage) PageCount

func (p *PastePage) PageCount(pageSize int) int

type PasteView

type PasteView struct {
	*Paste
	Top  *Paste
	Prev *Paste
}

type Query

type Query struct {
	Request  *http.Request
	Response http.ResponseWriter
	Action   string
	Args     []string
	User     string
}

func NewQuery

func NewQuery(w http.ResponseWriter, req *http.Request) *Query

type Server

type Server struct {
	Config   *Config
	Database *sql.DB
}

func New

func New(config *Config) (*Server, error)

New creates a new Gopaste server object and opens its database connection.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the server listening for incoming requests on the specified port.

func (*Server) ServeHTTP

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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