From 30aa5d8c2ddb49ec56596edad23b5c1043737366 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 17 May 2017 21:30:25 -0700 Subject: remove code --- vendor/github.com/Xe/asarfs/asarfs.go | 117 --------- vendor/github.com/Xe/asarfs/bench_test.go | 156 ------------ vendor/github.com/Xe/asarfs/runtest.go | 24 -- vendor/github.com/Xe/gopreload/doc.go | 7 - vendor/github.com/Xe/gopreload/preload.go | 26 -- vendor/github.com/Xe/ln/filter.go | 66 ----- vendor/github.com/Xe/ln/formatter.go | 100 -------- vendor/github.com/Xe/ln/logger.go | 141 ----------- vendor/github.com/Xe/ln/stack.go | 44 ---- vendor/github.com/gernest/front/front.go | 144 ----------- vendor/github.com/gorilla/feeds/atom.go | 163 ------------- vendor/github.com/gorilla/feeds/doc.go | 70 ------ vendor/github.com/gorilla/feeds/feed.go | 106 -------- vendor/github.com/gorilla/feeds/rss.go | 146 ----------- vendor/github.com/gorilla/feeds/uuid.go | 27 --- vendor/github.com/pkg/errors/errors.go | 269 --------------------- vendor/github.com/pkg/errors/stack.go | 178 -------------- vendor/github.com/urfave/negroni/doc.go | 25 -- vendor/github.com/urfave/negroni/logger.go | 35 --- vendor/github.com/urfave/negroni/negroni.go | 133 ---------- vendor/github.com/urfave/negroni/recovery.go | 65 ----- .../github.com/urfave/negroni/response_writer.go | 99 -------- vendor/github.com/urfave/negroni/static.go | 88 ------- 23 files changed, 2229 deletions(-) delete mode 100644 vendor/github.com/Xe/asarfs/asarfs.go delete mode 100644 vendor/github.com/Xe/asarfs/bench_test.go delete mode 100644 vendor/github.com/Xe/asarfs/runtest.go delete mode 100644 vendor/github.com/Xe/gopreload/doc.go delete mode 100644 vendor/github.com/Xe/gopreload/preload.go delete mode 100644 vendor/github.com/Xe/ln/filter.go delete mode 100644 vendor/github.com/Xe/ln/formatter.go delete mode 100644 vendor/github.com/Xe/ln/logger.go delete mode 100644 vendor/github.com/Xe/ln/stack.go delete mode 100644 vendor/github.com/gernest/front/front.go delete mode 100644 vendor/github.com/gorilla/feeds/atom.go delete mode 100644 vendor/github.com/gorilla/feeds/doc.go delete mode 100644 vendor/github.com/gorilla/feeds/feed.go delete mode 100644 vendor/github.com/gorilla/feeds/rss.go delete mode 100644 vendor/github.com/gorilla/feeds/uuid.go delete mode 100644 vendor/github.com/pkg/errors/errors.go delete mode 100644 vendor/github.com/pkg/errors/stack.go delete mode 100644 vendor/github.com/urfave/negroni/doc.go delete mode 100644 vendor/github.com/urfave/negroni/logger.go delete mode 100644 vendor/github.com/urfave/negroni/negroni.go delete mode 100644 vendor/github.com/urfave/negroni/recovery.go delete mode 100644 vendor/github.com/urfave/negroni/response_writer.go delete mode 100644 vendor/github.com/urfave/negroni/static.go (limited to 'vendor/github.com') diff --git a/vendor/github.com/Xe/asarfs/asarfs.go b/vendor/github.com/Xe/asarfs/asarfs.go deleted file mode 100644 index 7d18949..0000000 --- a/vendor/github.com/Xe/asarfs/asarfs.go +++ /dev/null @@ -1,117 +0,0 @@ -package asarfs - -import ( - "io" - "mime" - "net/http" - "os" - "path/filepath" - "strings" - - "layeh.com/asar" -) - -// ASARfs serves the contents of an asar archive as an HTTP handler. -type ASARfs struct { - fin *os.File - ar *asar.Entry - notFound http.Handler -} - -// Close closes the underlying file used for the asar archive. -func (a *ASARfs) Close() error { - return a.fin.Close() -} - -// Open satisfies the http.FileSystem interface for ASARfs. -func (a *ASARfs) Open(name string) (http.File, error) { - if name == "/" { - name = "/index.html" - } - - e := a.ar.Find(strings.Split(name, "/")[1:]...) - if e == nil { - return nil, os.ErrNotExist - } - - f := &file{ - Entry: e, - r: e.Open(), - } - - return f, nil -} - -// ServeHTTP satisfies the http.Handler interface for ASARfs. -func (a *ASARfs) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if r.RequestURI == "/" { - r.RequestURI = "/index.html" - } - - f := a.ar.Find(strings.Split(r.RequestURI, "/")[1:]...) - if f == nil { - a.notFound.ServeHTTP(w, r) - return - } - - ext := filepath.Ext(f.Name) - mimeType := mime.TypeByExtension(ext) - - w.Header().Add("Content-Type", mimeType) - f.WriteTo(w) -} - -// New creates a new ASARfs pointer based on the filepath to the archive and -// a HTTP handler to hit when a file is not found. -func New(archivePath string, notFound http.Handler) (*ASARfs, error) { - fin, err := os.Open(archivePath) - if err != nil { - return nil, err - } - - root, err := asar.Decode(fin) - if err != nil { - return nil, err - } - - a := &ASARfs{ - fin: fin, - ar: root, - notFound: notFound, - } - - return a, nil -} - -// file is an internal shim that mimics http.File for an asar entry. -type file struct { - *asar.Entry - r io.ReadSeeker -} - -func (f *file) Close() error { - f.r = nil - return nil -} - -func (f *file) Read(buf []byte) (n int, err error) { - return f.r.Read(buf) -} - -func (f *file) Seek(offset int64, whence int) (int64, error) { - return f.r.Seek(offset, whence) -} - -func (f *file) Readdir(count int) ([]os.FileInfo, error) { - result := []os.FileInfo{} - - for _, e := range f.Entry.Children { - result = append(result, e.FileInfo()) - } - - return result, nil -} - -func (f *file) Stat() (os.FileInfo, error) { - return f.Entry.FileInfo(), nil -} diff --git a/vendor/github.com/Xe/asarfs/bench_test.go b/vendor/github.com/Xe/asarfs/bench_test.go deleted file mode 100644 index fd332d5..0000000 --- a/vendor/github.com/Xe/asarfs/bench_test.go +++ /dev/null @@ -1,156 +0,0 @@ -// +build go1.8 - -package asarfs - -import ( - "fmt" - "io" - "io/ioutil" - "math/rand" - "net" - "net/http" - "os" - "testing" -) - -func BenchmarkHTTPFileSystem(b *testing.B) { - fs := http.FileServer(http.Dir(".")) - - l, s, err := setupHandler(fs) - if err != nil { - b.Fatal(err) - } - defer l.Close() - defer s.Close() - - url := fmt.Sprintf("http://%s", l.Addr()) - - for n := 0; n < b.N; n++ { - testHandler(url) - } -} - -func BenchmarkASARfs(b *testing.B) { - fs, err := New("./static.asar", http.HandlerFunc(do404)) - if err != nil { - b.Fatal(err) - } - - l, s, err := setupHandler(fs) - if err != nil { - b.Fatal(err) - } - defer l.Close() - defer s.Close() - - url := fmt.Sprintf("http://%s", l.Addr()) - - for n := 0; n < b.N; n++ { - testHandler(url) - } -} - -func BenchmarkPreloadedASARfs(b *testing.B) { - for n := 0; n < b.N; n++ { - testHandler(asarfsurl) - } -} - -func BenchmarkASARfsHTTPFilesystem(b *testing.B) { - fs, err := New("./static.asar", http.HandlerFunc(do404)) - if err != nil { - b.Fatal(err) - } - - l, s, err := setupHandler(http.FileServer(fs)) - if err != nil { - b.Fatal(err) - } - defer l.Close() - defer s.Close() - - url := fmt.Sprintf("http://%s", l.Addr()) - - for n := 0; n < b.N; n++ { - testHandler(url) - } -} - -func BenchmarkPreloadedASARfsHTTPFilesystem(b *testing.B) { - for n := 0; n < b.N; n++ { - testHandler(asarfshttpfsurl) - } -} - -func do404(w http.ResponseWriter, r *http.Request) { - http.Error(w, "Not found", http.StatusNotFound) -} - -func setupHandler(h http.Handler) (net.Listener, *http.Server, error) { - l, err := net.Listen("tcp", ":0") - if err != nil { - panic(err) - } - defer l.Close() - - s := &http.Server{ - Handler: h, - } - go s.ListenAndServe() - - return l, s, nil -} - -func testHandler(u string) error { - num := rand.Intn(9) - num++ - sub := rand.Intn(99) - - fname := fmt.Sprintf("/static/%d/%d%d.json", num, num, sub) - - resp, err := http.Get(u + fname) - if err != nil { - return err - } - defer resp.Body.Close() - - _, err = io.Copy(ioutil.Discard, resp.Body) - if err != nil { - panic(err) - } - - return nil -} - -var ( - asarfsurl string - asarfshttpfsurl string -) - -func TestMain(m *testing.M) { - go func() { - fs, err := New("./static.asar", http.HandlerFunc(do404)) - if err != nil { - } - - l, _, err := setupHandler(fs) - if err != nil { - } - - asarfsurl = fmt.Sprintf("http://%s", l.Addr().String()) - }() - - go func() { - fs, err := New("./static.asar", http.HandlerFunc(do404)) - if err != nil { - } - - l, _, err := setupHandler(http.FileServer(fs)) - if err != nil { - } - - asarfshttpfsurl = fmt.Sprintf("http://%s", l.Addr().String()) - }() - - os.Exit(m.Run()) -} diff --git a/vendor/github.com/Xe/asarfs/runtest.go b/vendor/github.com/Xe/asarfs/runtest.go deleted file mode 100644 index 4b839de..0000000 --- a/vendor/github.com/Xe/asarfs/runtest.go +++ /dev/null @@ -1,24 +0,0 @@ -// +build ignore - -package main - -import ( - "log" - "net/http" - "os" - - "github.com/Xe/asarfs" -) - -func do404(w http.ResponseWriter, r *http.Request) { - http.Error(w, "Not found", http.StatusNotFound) -} - -func main() { - fs, err := asarfs.New("./static.asar", http.HandlerFunc(do404)) - if err != nil { - log.Fatal(err) - } - - http.ListenAndServe(":"+os.Getenv("PORT"), fs) -} diff --git a/vendor/github.com/Xe/gopreload/doc.go b/vendor/github.com/Xe/gopreload/doc.go deleted file mode 100644 index 720c5c1..0000000 --- a/vendor/github.com/Xe/gopreload/doc.go +++ /dev/null @@ -1,7 +0,0 @@ -/* -Package gopreload is a bit of a hack to emulate the behavior of LD_PRELOAD [ld-preload]. -This allows you to have automatically starting instrumentation, etc. - -[ld-preload]: http://man7.org/linux/man-pages/man8/ld.so.8.html (see LD_PRELOAD section) -*/ -package gopreload diff --git a/vendor/github.com/Xe/gopreload/preload.go b/vendor/github.com/Xe/gopreload/preload.go deleted file mode 100644 index 1b5a0c9..0000000 --- a/vendor/github.com/Xe/gopreload/preload.go +++ /dev/null @@ -1,26 +0,0 @@ -//+build linux,go1.8 - -package gopreload - -import ( - "log" - "os" - "plugin" - "strings" -) - -func init() { - gpv := os.Getenv("GO_PRELOAD") - if gpv == "" { - return - } - - for _, elem := range strings.Split(gpv, ",") { - log.Printf("gopreload: trying to open: %s", elem) - _, err := plugin.Open(elem) - if err != nil { - log.Printf("%v from GO_PRELOAD cannot be loaded: %v", elem, err) - continue - } - } -} diff --git a/vendor/github.com/Xe/ln/filter.go b/vendor/github.com/Xe/ln/filter.go deleted file mode 100644 index 586efef..0000000 --- a/vendor/github.com/Xe/ln/filter.go +++ /dev/null @@ -1,66 +0,0 @@ -package ln - -import ( - "io" - "sync" -) - -// Filter interface for defining chain filters -type Filter interface { - Apply(Event) bool - Run() - Close() -} - -// FilterFunc allows simple functions to implement the Filter interface -type FilterFunc func(e Event) bool - -// Apply implements the Filter interface -func (ff FilterFunc) Apply(e Event) bool { - return ff(e) -} - -// Run implements the Filter interface -func (ff FilterFunc) Run() {} - -// Close implements the Filter interface -func (ff FilterFunc) Close() {} - -// WriterFilter implements a filter, which arbitrarily writes to an io.Writer -type WriterFilter struct { - sync.Mutex - Out io.Writer - Formatter Formatter -} - -// NewWriterFilter creates a filter to add to the chain -func NewWriterFilter(out io.Writer, format Formatter) *WriterFilter { - if format == nil { - format = DefaultFormatter - } - return &WriterFilter{ - Out: out, - Formatter: format, - } -} - -// Apply implements the Filter interface -func (w *WriterFilter) Apply(e Event) bool { - output, err := w.Formatter.Format(e) - if err == nil { - w.Lock() - w.Out.Write(output) - w.Unlock() - } - - return true -} - -// Run implements the Filter interface -func (w *WriterFilter) Run() {} - -// Close implements the Filter interface -func (w *WriterFilter) Close() {} - -// NilFilter is safe to return as a Filter, but does nothing -var NilFilter = FilterFunc(func(e Event) bool { return true }) diff --git a/vendor/github.com/Xe/ln/formatter.go b/vendor/github.com/Xe/ln/formatter.go deleted file mode 100644 index 9d67139..0000000 --- a/vendor/github.com/Xe/ln/formatter.go +++ /dev/null @@ -1,100 +0,0 @@ -package ln - -import ( - "bytes" - "fmt" - "time" -) - -var ( - // DefaultTimeFormat represents the way in which time will be formatted by default - DefaultTimeFormat = time.RFC3339 -) - -// Formatter defines the formatting of events -type Formatter interface { - Format(Event) ([]byte, error) -} - -// DefaultFormatter is the default way in which to format events -var DefaultFormatter Formatter - -func init() { - DefaultFormatter = NewTextFormatter() -} - -// TextFormatter formats events as key value pairs. -// Any remaining text not wrapped in an instance of `F` will be -// placed at the end. -type TextFormatter struct { - TimeFormat string -} - -// NewTextFormatter returns a Formatter that outputs as text. -func NewTextFormatter() Formatter { - return &TextFormatter{TimeFormat: DefaultTimeFormat} -} - -// Format implements the Formatter interface -func (t *TextFormatter) Format(e Event) ([]byte, error) { - var writer bytes.Buffer - - writer.WriteString("time=\"") - writer.WriteString(e.Time.Format(t.TimeFormat)) - writer.WriteString("\"") - - for k, v := range e.Data { - writer.WriteByte(' ') - if shouldQuote(k) { - writer.WriteString(fmt.Sprintf("%q", k)) - } else { - writer.WriteString(k) - } - - writer.WriteByte('=') - - switch v.(type) { - case string: - vs, _ := v.(string) - if shouldQuote(vs) { - fmt.Fprintf(&writer, "%q", vs) - } else { - writer.WriteString(vs) - } - case error: - tmperr, _ := v.(error) - es := tmperr.Error() - - if shouldQuote(es) { - fmt.Fprintf(&writer, "%q", es) - } else { - writer.WriteString(es) - } - case time.Time: - tmptime, _ := v.(time.Time) - writer.WriteString(tmptime.Format(time.RFC3339)) - default: - fmt.Fprint(&writer, v) - } - } - - if len(e.Message) > 0 { - fmt.Fprintf(&writer, " _msg=%q", e.Message) - } - - writer.WriteByte('\n') - return writer.Bytes(), nil -} - -func shouldQuote(s string) bool { - for _, b := range s { - if !((b >= 'A' && b <= 'Z') || - (b >= 'a' && b <= 'z') || - (b >= '0' && b <= '9') || - (b == '-' || b == '.' || b == '#' || - b == '/' || b == '_')) { - return true - } - } - return false -} diff --git a/vendor/github.com/Xe/ln/logger.go b/vendor/github.com/Xe/ln/logger.go deleted file mode 100644 index cdfe89e..0000000 --- a/vendor/github.com/Xe/ln/logger.go +++ /dev/null @@ -1,141 +0,0 @@ -package ln - -import ( - "fmt" - "os" - "time" - - "github.com/pkg/errors" -) - -// Logger holds the current priority and list of filters -type Logger struct { - Filters []Filter -} - -// DefaultLogger is the default implementation of Logger -var DefaultLogger *Logger - -func init() { - var defaultFilters []Filter - - // Default to STDOUT for logging, but allow LN_OUT to change it. - out := os.Stdout - if os.Getenv("LN_OUT") == "" { - out = os.Stderr - } - - defaultFilters = append(defaultFilters, NewWriterFilter(out, nil)) - - DefaultLogger = &Logger{ - Filters: defaultFilters, - } - -} - -// F is a key-value mapping for structured data. -type F map[string]interface{} - -type Fer interface { - F() map[string]interface{} -} - -// Event represents an event -type Event struct { - Time time.Time - Data F - Message string -} - -// Log is the generic logging method. -func (l *Logger) Log(xs ...interface{}) { - var bits []interface{} - event := Event{Time: time.Now()} - - addF := func(bf F) { - if event.Data == nil { - event.Data = bf - } else { - for k, v := range bf { - event.Data[k] = v - } - } - } - - // Assemble the event - for _, b := range xs { - if bf, ok := b.(F); ok { - addF(bf) - } else if fer, ok := b.(Fer); ok { - addF(F(fer.F())) - } else { - bits = append(bits, b) - } - } - - event.Message = fmt.Sprint(bits...) - - if os.Getenv("LN_DEBUG_ALL_EVENTS") == "1" { - frame := callersFrame() - if event.Data == nil { - event.Data = make(F) - } - event.Data["_lineno"] = frame.lineno - event.Data["_function"] = frame.function - event.Data["_filename"] = frame.filename - } - - l.filter(event) -} - -func (l *Logger) filter(e Event) { - for _, f := range l.Filters { - if !f.Apply(e) { - return - } - } -} - -// Error logs an error and information about the context of said error. -func (l *Logger) Error(err error, xs ...interface{}) { - data := F{} - frame := callersFrame() - - data["_lineno"] = frame.lineno - data["_function"] = frame.function - data["_filename"] = frame.filename - data["err"] = err - - cause := errors.Cause(err) - if cause != nil { - data["cause"] = cause.Error() - } - - xs = append(xs, data) - - l.Log(xs...) -} - -// Fatal logs this set of values, then exits with status code 1. -func (l *Logger) Fatal(xs ...interface{}) { - l.Log(xs...) - - os.Exit(1) -} - -// Default Implementation - -// Log is the generic logging method. -func Log(xs ...interface{}) { - DefaultLogger.Log(xs...) -} - -// Error logs an error and information about the context of said error. -func Error(err error, xs ...interface{}) { - DefaultLogger.Error(err, xs...) -} - -// Fatal logs this set of values, then exits with status code 1. -func Fatal(xs ...interface{}) { - DefaultLogger.Fatal(xs...) -} diff --git a/vendor/github.com/Xe/ln/stack.go b/vendor/github.com/Xe/ln/stack.go deleted file mode 100644 index 1cf1e7a..0000000 --- a/vendor/github.com/Xe/ln/stack.go +++ /dev/null @@ -1,44 +0,0 @@ -package ln - -import ( - "os" - "runtime" - "strings" -) - -type frame struct { - filename string - function string - lineno int -} - -// skips 2 frames, since Caller returns the current frame, and we need -// the caller's caller. -func callersFrame() frame { - var out frame - pc, file, line, ok := runtime.Caller(3) - if !ok { - return out - } - srcLoc := strings.LastIndex(file, "/src/") - if srcLoc >= 0 { - file = file[srcLoc+5:] - } - out.filename = file - out.function = functionName(pc) - out.lineno = line - - return out -} - -func functionName(pc uintptr) string { - fn := runtime.FuncForPC(pc) - if fn == nil { - return "???" - } - name := fn.Name() - beg := strings.LastIndex(name, string(os.PathSeparator)) - return name[beg+1:] - // end := strings.LastIndex(name, string(os.PathSeparator)) - // return name[end+1 : len(name)] -} diff --git a/vendor/github.com/gernest/front/front.go b/vendor/github.com/gernest/front/front.go deleted file mode 100644 index f4c6f25..0000000 --- a/vendor/github.com/gernest/front/front.go +++ /dev/null @@ -1,144 +0,0 @@ -// Package front is a frontmatter extraction library. -package front - -import ( - "bufio" - "bytes" - "encoding/json" - "errors" - "io" - "strings" - - "gopkg.in/yaml.v2" -) - -var ( - //ErrIsEmpty is an error indicating no front matter was found - ErrIsEmpty = errors.New("front: an empty file") - - //ErrUnknownDelim is returned when the delimiters are not known by the - //FrontMatter implementation. - ErrUnknownDelim = errors.New("front: unknown delim") -) - -type ( - //HandlerFunc is an interface for a function that process front matter text. - HandlerFunc func(string) (map[string]interface{}, error) -) - -//Matter is all what matters here. -type Matter struct { - handlers map[string]HandlerFunc -} - -//NewMatter creates a new Matter instance -func NewMatter() *Matter { - return &Matter{handlers: make(map[string]HandlerFunc)} -} - -//Handle registers a handler for the given frontmatter delimiter -func (m *Matter) Handle(delim string, fn HandlerFunc) { - m.handlers[delim] = fn -} - -// Parse parses the input and extract the frontmatter -func (m *Matter) Parse(input io.Reader) (front map[string]interface{}, body string, err error) { - return m.parse(input) -} -func (m *Matter) parse(input io.Reader) (front map[string]interface{}, body string, err error) { - var getFront = func(f string) string { - return strings.TrimSpace(f[3:]) - } - f, body, err := m.splitFront(input) - if err != nil { - return nil, "", err - } - h := m.handlers[f[:3]] - front, err = h(getFront(f)) - if err != nil { - return nil, "", err - } - return front, body, nil - -} -func sniffDelim(input []byte) (string, error) { - if len(input) < 4 { - return "", ErrIsEmpty - } - return string(input[:3]), nil -} - -func (m *Matter) splitFront(input io.Reader) (front, body string, err error) { - bufsize := 1024 * 1024 - buf := make([]byte, bufsize) - - s := bufio.NewScanner(input) - // Necessary so we can handle larger than default 4096b buffer - s.Buffer(buf, bufsize) - - rst := make([]string, 2) - s.Split(m.split) - n := 0 - for s.Scan() { - if n == 0 { - rst[0] = s.Text() - } else if n == 1 { - rst[1] = s.Text() - } - n++ - } - if err = s.Err(); err != nil { - return - } - return rst[0], rst[1], nil -} - -//split implements bufio.SplitFunc for spliting fron matter from the body text. -func (m *Matter) split(data []byte, atEOF bool) (advance int, token []byte, err error) { - if atEOF && len(data) == 0 { - return 0, nil, nil - } - delim, err := sniffDelim(data) - if err != nil { - return 0, nil, err - } - if _, ok := m.handlers[delim]; !ok { - return 0, nil, ErrUnknownDelim - } - if x := bytes.Index(data, []byte(delim)); x >= 0 { - // check the next delim index - if next := bytes.Index(data[x+len(delim):], []byte(delim)); next > 0 { - return next + len(delim), dropSpace(data[:next+len(delim)]), nil - } - return len(data), dropSpace(data[x+len(delim):]), nil - } - if atEOF { - return len(data), data, nil - } - return 0, nil, nil -} - -func dropSpace(d []byte) []byte { - return bytes.TrimSpace(d) -} - -//JSONHandler implements HandlerFunc interface. It extracts front matter data from the given -// string argument by interpreting it as a json string. -func JSONHandler(front string) (map[string]interface{}, error) { - var rst interface{} - err := json.Unmarshal([]byte(front), &rst) - if err != nil { - return nil, err - } - return rst.(map[string]interface{}), nil -} - -//YAMLHandler decodes ymal string into a go map[string]interface{} -func YAMLHandler(front string) (map[string]interface{}, error) { - out := make(map[string]interface{}) - err := yaml.Unmarshal([]byte(front), out) - if err != nil { - return nil, err - } - return out, nil -} diff --git a/vendor/github.com/gorilla/feeds/atom.go b/vendor/github.com/gorilla/feeds/atom.go deleted file mode 100644 index 512976b..0000000 --- a/vendor/github.com/gorilla/feeds/atom.go +++ /dev/null @@ -1,163 +0,0 @@ -package feeds - -import ( - "encoding/xml" - "fmt" - "net/url" - "strconv" - "time" -) - -// Generates Atom feed as XML - -const ns = "http://www.w3.org/2005/Atom" - -type AtomPerson struct { - Name string `xml:"name,omitempty"` - Uri string `xml:"uri,omitempty"` - Email string `xml:"email,omitempty"` -} - -type AtomSummary struct { - XMLName xml.Name `xml:"summary"` - Content string `xml:",chardata"` - Type string `xml:"type,attr"` -} - -type AtomContent struct { - XMLName xml.Name `xml:"content"` - Content string `xml:",chardata"` - Type string `xml:"type,attr"` -} - -type AtomAuthor struct { - XMLName xml.Name `xml:"author"` - AtomPerson -} - -type AtomContributor struct { - XMLName xml.Name `xml:"contributor"` - AtomPerson -} - -type AtomEntry struct { - XMLName xml.Name `xml:"entry"` - Xmlns string `xml:"xmlns,attr,omitempty"` - Title string `xml:"title"` // required - Updated string `xml:"updated"` // required - Id string `xml:"id"` // required - Category string `xml:"category,omitempty"` - Content *AtomContent - Rights string `xml:"rights,omitempty"` - Source string `xml:"source,omitempty"` - Published string `xml:"published,omitempty"` - Contributor *AtomContributor - Link *AtomLink // required if no child 'content' elements - Summary *AtomSummary // required if content has src or content is base64 - Author *AtomAuthor // required if feed lacks an author -} - -type AtomLink struct { - //Atom 1.0 - XMLName xml.Name `xml:"link"` - Href string `xml:"href,attr"` - Rel string `xml:"rel,attr,omitempty"` - Type string `xml:"type,attr,omitempty"` - Length string `xml:"length,attr,omitempty"` -} - -type AtomFeed struct { - XMLName xml.Name `xml:"feed"` - Xmlns string `xml:"xmlns,attr"` - Title string `xml:"title"` // required - Id string `xml:"id"` // required - Updated string `xml:"updated"` // required - Category string `xml:"category,omitempty"` - Icon string `xml:"icon,omitempty"` - Logo string `xml:"logo,omitempty"` - Rights string `xml:"rights,omitempty"` // copyright used - Subtitle string `xml:"subtitle,omitempty"` - Link *AtomLink - Author *AtomAuthor `xml:"author,omitempty"` - Contributor *AtomContributor - Entries []*AtomEntry -} - -type Atom struct { - *Feed -} - -func newAtomEntry(i *Item) *AtomEntry { - id := i.Id - // assume the description is html - c := &AtomContent{Content: i.Description, Type: "html"} - - if len(id) == 0 { - // if there's no id set, try to create one, either from data or just a uuid - if len(i.Link.Href) > 0 && (!i.Created.IsZero() || !i.Updated.IsZero()) { - dateStr := anyTimeFormat("2006-01-02", i.Updated, i.Created) - host, path := i.Link.Href, "/invalid.html" - if url, err := url.Parse(i.Link.Href); err == nil { - host, path = url.Host, url.Path - } - id = fmt.Sprintf("tag:%s,%s:%s", host, dateStr, path) - } else { - id = "urn:uuid:" + NewUUID().String() - } - } - var name, email string - if i.Author != nil { - name, email = i.Author.Name, i.Author.Email - } - - x := &AtomEntry{ - Title: i.Title, - Link: &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel, Type: i.Link.Type}, - Content: c, - Id: id, - Updated: anyTimeFormat(time.RFC3339, i.Updated, i.Created), - } - - intLength, err := strconv.ParseInt(i.Link.Length, 10, 64) - - if err == nil && (intLength > 0 || i.Link.Type != "") { - i.Link.Rel = "enclosure" - x.Link = &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel, Type: i.Link.Type, Length: i.Link.Length} - } - - if len(name) > 0 || len(email) > 0 { - x.Author = &AtomAuthor{AtomPerson: AtomPerson{Name: name, Email: email}} - } - return x -} - -// create a new AtomFeed with a generic Feed struct's data -func (a *Atom) AtomFeed() *AtomFeed { - updated := anyTimeFormat(time.RFC3339, a.Updated, a.Created) - feed := &AtomFeed{ - Xmlns: ns, - Title: a.Title, - Link: &AtomLink{Href: a.Link.Href, Rel: a.Link.Rel}, - Subtitle: a.Description, - Id: a.Link.Href, - Updated: updated, - Rights: a.Copyright, - } - if a.Author != nil { - feed.Author = &AtomAuthor{AtomPerson: AtomPerson{Name: a.Author.Name, Email: a.Author.Email}} - } - for _, e := range a.Items { - feed.Entries = append(feed.Entries, newAtomEntry(e)) - } - return feed -} - -// return an XML-Ready object for an Atom object -func (a *Atom) FeedXml() interface{} { - return a.AtomFeed() -} - -// return an XML-ready object for an AtomFeed object -func (a *AtomFeed) FeedXml() interface{} { - return a -} diff --git a/vendor/github.com/gorilla/feeds/doc.go b/vendor/github.com/gorilla/feeds/doc.go deleted file mode 100644 index 5b005ea..0000000 --- a/vendor/github.com/gorilla/feeds/doc.go +++ /dev/null @@ -1,70 +0,0 @@ -/* -Syndication (feed) generator library for golang. - -Installing - - go get github.com/gorilla/feeds - -Feeds provides a simple, generic Feed interface with a generic Item object as well as RSS and Atom specific RssFeed and AtomFeed objects which allow access to all of each spec's defined elements. - -Examples - -Create a Feed and some Items in that feed using the generic interfaces: - - import ( - "time" - . "github.com/gorilla/feeds - ) - - now = time.Now() - - feed := &Feed{ - Title: "jmoiron.net blog", - Link: &Link{Href: "http://jmoiron.net/blog"}, - Description: "discussion about tech, footie, photos", - Author: &Author{Name: "Jason Moiron", Email: "jmoiron@jmoiron.net"}, - Created: now, - Copyright: "This work is copyright © Benjamin Button", - } - - feed.Items = []*Item{ - &Item{ - Title: "Limiting Concurrency in Go", - Link: &Link{Href: "http://jmoiron.net/blog/limiting-concurrency-in-go/"}, - Description: "A discussion on controlled parallelism in golang", - Author: &Author{Name: "Jason Moiron", Email: "jmoiron@jmoiron.net"}, - Created: now, - }, - &Item{ - Title: "Logic-less Template Redux", - Link: &Link{Href: "http://jmoiron.net/blog/logicless-template-redux/"}, - Description: "More thoughts on logicless templates", - Created: now, - }, - &Item{ - Title: "Idiomatic Code Reuse in Go", - Link: &Link{Href: "http://jmoiron.net/blog/idiomatic-code-reuse-in-go/"}, - Description: "How to use interfaces effectively", - Created: now, - }, - } - -From here, you can output Atom or RSS versions of this feed easily - - atom, err := feed.ToAtom() - rss, err := feed.ToRss() - -You can also get access to the underlying objects that feeds uses to export its XML - - atomFeed := &Atom{feed}.AtomFeed() - rssFeed := &Rss{feed}.RssFeed() - -From here, you can modify or add each syndication's specific fields before outputting - - atomFeed.Subtitle = "plays the blues" - atom, err := ToXML(atomFeed) - rssFeed.Generator = "gorilla/feeds v1.0 (github.com/gorilla/feeds)" - rss, err := ToXML(rssFeed) - -*/ -package feeds diff --git a/vendor/github.com/gorilla/feeds/feed.go b/vendor/github.com/gorilla/feeds/feed.go deleted file mode 100644 index fe4833e..0000000 --- a/vendor/github.com/gorilla/feeds/feed.go +++ /dev/null @@ -1,106 +0,0 @@ -package feeds - -import ( - "encoding/xml" - "io" - "time" -) - -type Link struct { - Href, Rel, Type, Length string -} - -type Author struct { - Name, Email string -} - -type Item struct { - Title string - Link *Link - Author *Author - Description string // used as description in rss, summary in atom - Id string // used as guid in rss, id in atom - Updated time.Time - Created time.Time -} - -type Feed struct { - Title string - Link *Link - Description string - Author *Author - Updated time.Time - Created time.Time - Id string - Subtitle string - Items []*Item - Copyright string -} - -// add a new Item to a Feed -func (f *Feed) Add(item *Item) { - f.Items = append(f.Items, item) -} - -// returns the first non-zero time formatted as a string or "" -func anyTimeFormat(format string, times ...time.Time) string { - for _, t := range times { - if !t.IsZero() { - return t.Format(format) - } - } - return "" -} - -// interface used by ToXML to get a object suitable for exporting XML. -type XmlFeed interface { - FeedXml() interface{} -} - -// turn a feed object (either a Feed, AtomFeed, or RssFeed) into xml -// returns an error if xml marshaling fails -func ToXML(feed XmlFeed) (string, error) { - x := feed.FeedXml() - data, err := xml.MarshalIndent(x, "", " ") - if err != nil { - return "", err - } - // strip empty line from default xml header - s := xml.Header[:len(xml.Header)-1] + string(data) - return s, nil -} - -// Write a feed object (either a Feed, AtomFeed, or RssFeed) as XML into -// the writer. Returns an error if XML marshaling fails. -func WriteXML(feed XmlFeed, w io.Writer) error { - x := feed.FeedXml() - // write default xml header, without the newline - if _, err := w.Write([]byte(xml.Header[:len(xml.Header)-1])); err != nil { - return err - } - e := xml.NewEncoder(w) - e.Indent("", " ") - return e.Encode(x) -} - -// creates an Atom representation of this feed -func (f *Feed) ToAtom() (string, error) { - a := &Atom{f} - return ToXML(a) -} - -// Writes an Atom representation of this feed to the writer. -func (f *Feed) WriteAtom(w io.Writer) error { - return WriteXML(&Atom{f}, w) -} - -// creates an Rss representation of this feed -func (f *Feed) ToRss() (string, error) { - r := &Rss{f} - return ToXML(r) -} - -// Writes an RSS representation of this feed to the writer. -func (f *Feed) WriteRss(w io.Writer) error { - return WriteXML(&Rss{f}, w) -} diff --git a/vendor/github.com/gorilla/feeds/rss.go b/vendor/github.com/gorilla/feeds/rss.go deleted file mode 100644 index 3381f74..0000000 --- a/vendor/github.com/gorilla/feeds/rss.go +++ /dev/null @@ -1,146 +0,0 @@ -package feeds - -// rss support -// validation done according to spec here: -// http://cyber.law.harvard.edu/rss/rss.html - -import ( - "encoding/xml" - "fmt" - "strconv" - "time" -) - -// private wrapper around the RssFeed which gives us the .. xml -type rssFeedXml struct { - XMLName xml.Name `xml:"rss"` - Version string `xml:"version,attr"` - Channel *RssFeed -} - -type RssImage struct { - XMLName xml.Name `xml:"image"` - Url string `xml:"url"` - Title string `xml:"title"` - Link string `xml:"link"` - Width int `xml:"width,omitempty"` - Height int `xml:"height,omitempty"` -} - -type RssTextInput struct { - XMLName xml.Name `xml:"textInput"` - Title string `xml:"title"` - Description string `xml:"description"` - Name string `xml:"name"` - Link string `xml:"link"` -} - -type RssFeed struct { - XMLName xml.Name `xml:"channel"` - Title string `xml:"title"` // required - Link string `xml:"link"` // required - Description string `xml:"description"` // required - Language string `xml:"language,omitempty"` - Copyright string `xml:"copyright,omitempty"` - ManagingEditor string `xml:"managingEditor,omitempty"` // Author used - WebMaster string `xml:"webMaster,omitempty"` - PubDate string `xml:"pubDate,omitempty"` // created or updated - LastBuildDate string `xml:"lastBuildDate,omitempty"` // updated used - Category string `xml:"category,omitempty"` - Generator string `xml:"generator,omitempty"` - Docs string `xml:"docs,omitempty"` - Cloud string `xml:"cloud,omitempty"` - Ttl int `xml:"ttl,omitempty"` - Rating string `xml:"rating,omitempty"` - SkipHours string `xml:"skipHours,omitempty"` - SkipDays string `xml:"skipDays,omitempty"` - Image *RssImage - TextInput *RssTextInput - Items []*RssItem -} - -type RssItem struct { - XMLName xml.Name `xml:"item"` - Title string `xml:"title"` // required - Link string `xml:"link"` // required - Description string `xml:"description"` // required - Author string `xml:"author,omitempty"` - Category string `xml:"category,omitempty"` - Comments string `xml:"comments,omitempty"` - Enclosure *RssEnclosure - Guid string `xml:"guid,omitempty"` // Id used - PubDate string `xml:"pubDate,omitempty"` // created or updated - Source string `xml:"source,omitempty"` -} - -type RssEnclosure struct { - //RSS 2.0 - XMLName xml.Name `xml:"enclosure"` - Url string `xml:"url,attr"` - Length string `xml:"length,attr"` - Type string `xml:"type,attr"` -} - -type Rss struct { - *Feed -} - -// create a new RssItem with a generic Item struct's data -func newRssItem(i *Item) *RssItem { - item := &RssItem{ - Title: i.Title, - Link: i.Link.Href, - Description: i.Description, - Guid: i.Id, - PubDate: anyTimeFormat(time.RFC1123Z, i.Created, i.Updated), - } - - intLength, err := strconv.ParseInt(i.Link.Length, 10, 64) - - if err == nil && (intLength > 0 || i.Link.Type != "") { - item.Enclosure = &RssEnclosure{Url: i.Link.Href, Type: i.Link.Type, Length: i.Link.Length} - } - if i.Author != nil { - item.Author = i.Author.Name - } - return item -} - -// create a new RssFeed with a generic Feed struct's data -func (r *Rss) RssFeed() *RssFeed { - pub := anyTimeFormat(time.RFC1123Z, r.Created, r.Updated) - build := anyTimeFormat(time.RFC1123Z, r.Updated) - author := "" - if r.Author != nil { - author = r.Author.Email - if len(r.Author.Name) > 0 { - author = fmt.Sprintf("%s (%s)", r.Author.Email, r.Author.Name) - } - } - - channel := &RssFeed{ - Title: r.Title, - Link: r.Link.Href, - Description: r.Description, - ManagingEditor: author, - PubDate: pub, - LastBuildDate: build, - Copyright: r.Copyright, - } - for _, i := range r.Items { - channel.Items = append(channel.Items, newRssItem(i)) - } - return channel -} - -// return an XML-Ready object for an Rss object -func (r *Rss) FeedXml() interface{} { - // only generate version 2.0 feeds for now - return r.RssFeed().FeedXml() - -} - -// return an XML-ready object for an RssFeed object -func (r *RssFeed) FeedXml() interface{} { - return &rssFeedXml{Version: "2.0", Channel: r} -} diff --git a/vendor/github.com/gorilla/feeds/uuid.go b/vendor/github.com/gorilla/feeds/uuid.go deleted file mode 100644 index 51bbafe..0000000 --- a/vendor/github.com/gorilla/feeds/uuid.go +++ /dev/null @@ -1,27 +0,0 @@ -package feeds - -// relevant bits from https://github.com/abneptis/GoUUID/blob/master/uuid.go - -import ( - "crypto/rand" - "fmt" -) - -type UUID [16]byte - -// create a new uuid v4 -func NewUUID() *UUID { - u := &UUID{} - _, err := rand.Read(u[:16]) - if err != nil { - panic(err) - } - - u[8] = (u[8] | 0x80) & 0xBf - u[6] = (u[6] | 0x40) & 0x4f - return u -} - -func (u *UUID) String() string { - return fmt.Sprintf("%x-%x-%x-%x-%x", u[:4], u[4:6], u[6:8], u[8:10], u[10:]) -} diff --git a/vendor/github.com/pkg/errors/errors.go b/vendor/github.com/pkg/errors/errors.go deleted file mode 100644 index 842ee80..0000000 --- a/vendor/github.com/pkg/errors/errors.go +++ /dev/null @@ -1,269 +0,0 @@ -// Package errors provides simple error handling primitives. -// -// The traditional error handling idiom in Go is roughly akin to -// -// if err != nil { -// return err -// } -// -// which applied recursively up the call stack results in error reports -// without context or debugging information. The errors package allows -// programmers to add context to the failure path in their code in a way -// that does not destroy the original value of the error. -// -// Adding context to an error -// -// The errors.Wrap function returns a new error that adds context to the -// original error by recording a stack trace at the point Wrap is called, -// and the supplied message. For example -// -// _, err := ioutil.ReadAll(r) -// if err != nil { -// return errors.Wrap(err, "read failed") -// } -// -// If additional control is required the errors.WithStack and errors.WithMessage -// functions destructure errors.Wrap into its component operations of annotating -// an error with a stack trace and an a message, respectively. -// -// Retrieving the cause of an error -// -// Using errors.Wrap constructs a stack of errors, adding context to the -// preceding error. Depending on the nature of the error it may be necessary -// to reverse the operation of errors.Wrap to retrieve the original error -// for inspection. Any error value which implements this interface -// -// type causer interface { -// Cause() error -// } -// -// can be inspected by errors.Cause. errors.Cause will recursively retrieve -// the topmost error which does not implement causer, which is assumed to be -// the original cause. For example: -// -// switch err := errors.Cause(err).(type) { -// case *MyError: -// // handle specifically -// default: -// // unknown error -// } -// -// causer interface is not exported by this package, but is considered a part -// of stable public API. -// -// Formatted printing of errors -// -// All error values returned from this package implement fmt.Formatter and can -// be formatted by the fmt package. The following verbs are supported -// -// %s print the error. If the error has a Cause it will be -// printed recursively -// %v see %s -// %+v extended format. Each Frame of the error's StackTrace will -// be printed in detail. -// -// Retrieving the stack trace of an error or wrapper -// -// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are -// invoked. This information can be retrieved with the following interface. -// -// type stackTracer interface { -// StackTrace() errors.StackTrace -// } -// -// Where errors.StackTrace is defined as -// -// type StackTrace []Frame -// -// The Frame type represents a call site in the stack trace. Frame supports -// the fmt.Formatter interface that can be used for printing information about -// the stack trace of this error. For example: -// -// if err, ok := err.(stackTracer); ok { -// for _, f := range err.StackTrace() { -// fmt.Printf("%+s:%d", f) -// } -// } -// -// stackTracer interface is not exported by this package, but is considered a part -// of stable public API. -// -// See the documentation for Frame.Format for more details. -package errors - -import ( - "fmt" - "io" -) - -// New returns an error with the supplied message. -// New also records the stack trace at the point it was called. -func New(message string) error { - return &fundamental{ - msg: message, - stack: callers(), - } -} - -// Errorf formats according to a format specifier and returns the string -// as a value that satisfies error. -// Errorf also records the stack trace at the point it was called. -func Errorf(format string, args ...interface{}) error { - return &fundamental{ - msg: fmt.Sprintf(format, args...), - stack: callers(), - } -} - -// fundamental is an error that has a message and a stack, but no caller. -type fundamental struct { - msg string - *stack -} - -func (f *fundamental) Error() string { return f.msg } - -func (f *fundamental) Format(s fmt.State, verb rune) { - switch verb { - case 'v': - if s.Flag('+') { - io.WriteString(s, f.msg) - f.stack.Format(s, verb) - return - } - fallthrough - case 's': - io.WriteString(s, f.msg) - case 'q': - fmt.Fprintf(s, "%q", f.msg) - } -} - -// WithStack annotates err with a stack trace at the point WithStack was called. -// If err is nil, WithStack returns nil. -func WithStack(err error) error { - if err == nil { - return nil - } - return &withStack{ - err, - callers(), - } -} - -type withStack struct { - error - *stack -} - -func (w *withStack) Cause() error { return w.error } - -func (w *withStack) Format(s fmt.State, verb rune) { - switch verb { - case 'v': - if s.Flag('+') { - fmt.Fprintf(s, "%+v", w.Cause()) - w.stack.Format(s, verb) - return - } - fallthrough - case 's': - io.WriteString(s, w.Error()) - case 'q': - fmt.Fprintf(s, "%q", w.Error()) - } -} - -// Wrap returns an error annotating err with a stack trace -// at the point Wrap is called, and the supplied message. -// If err is nil, Wrap returns nil. -func Wrap(err error, message string) error { - if err == nil { - return nil - } - err = &withMessage{ - cause: err, - msg: message, - } - return &withStack{ - err, - callers(), - } -} - -// Wrapf returns an error annotating err with a stack trace -// at the point Wrapf is call, and the format specifier. -// If err is nil, Wrapf returns nil. -func Wrapf(err error, format string, args ...interface{}) error { - if err == nil { - return nil - } - err = &withMessage{ - cause: err, - msg: fmt.Sprintf(format, args...), - } - return &withStack{ - err, - callers(), - } -} - -// WithMessage annotates err with a new message. -// If err is nil, WithMessage returns nil. -func WithMessage(err error, message string) error { - if err == nil { - return nil - } - return &withMessage{ - cause: err, - msg: message, - } -} - -type withMessage struct { - cause error - msg string -} - -func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() } -func (w *withMessage) Cause() error { return w.cause } - -func (w *withMessage) Format(s fmt.State, verb rune) { - switch verb { - case 'v': - if s.Flag('+') { - fmt.Fprintf(s, "%+v\n", w.Cause()) - io.WriteString(s, w.msg) - return - } - fallthrough - case 's', 'q': - io.WriteString(s, w.Error()) - } -} - -// Cause returns the underlying cause of the error, if possible. -// An error value has a cause if it implements the following -// interface: -// -// type causer interface { -// Cause() error -// } -// -// If the error does not implement Cause, the original error will -// be returned. If the error is nil, nil will be returned without further -// investigation. -func Cause(err error) error { - type causer interface { - Cause() error - } - - for err != nil { - cause, ok := err.(causer) - if !ok { - break - } - err = cause.Cause() - } - return err -} diff --git a/vendor/github.com/pkg/errors/stack.go b/vendor/github.com/pkg/errors/stack.go deleted file mode 100644 index 6b1f289..0000000 --- a/vendor/github.com/pkg/errors/stack.go +++ /dev/null @@ -1,178 +0,0 @@ -package errors - -import ( - "fmt" - "io" - "path" - "runtime" - "strings" -) - -// Frame represents a program counter inside a stack frame. -type Frame uintptr - -// pc returns the program counter for this frame; -// multiple frames may have the same PC value. -func (f Frame) pc() uintptr { return uintptr(f) - 1 } - -// file returns the full path to the file that contains the -// function for this Frame's pc. -func (f Frame) file() string { - fn := runtime.FuncForPC(f.pc()) - if fn == nil { - return "unknown" - } - file, _ := fn.FileLine(f.pc()) - return file -} - -// line returns the line number of source code of the -// function for this Frame's pc. -func (f Frame) line() int { - fn := runtime.FuncForPC(f.pc()) - if fn == nil { - return 0 - } - _, line := fn.FileLine(f.pc()) - return line -} - -// Format formats the frame according to the fmt.Formatter interface. -// -// %s source file -// %d source line -// %n function name -// %v equivalent to %s:%d -// -// Format accepts flags that alter the printing of some verbs, as follows: -// -// %+s path of source file relative to the compile time GOPATH -// %+v equivalent to %+s:%d -func (f Frame) Format(s fmt.State, verb rune) { - switch verb { - case 's': - switch { - case s.Flag('+'): - pc := f.pc() - fn := runtime.FuncForPC(pc) - if fn == nil { - io.WriteString(s, "unknown") - } else { - file, _ := fn.FileLine(pc) - fmt.Fprintf(s, "%s\n\t%s", fn.Name(), file) - } - default: - io.WriteString(s, path.Base(f.file())) - } - case 'd': - fmt.Fprintf(s, "%d", f.line()) - case 'n': - name := runtime.FuncForPC(f.pc()).Name() - io.WriteString(s, funcname(name)) - case 'v': - f.Format(s, 's') - io.WriteString(s, ":") - f.Format(s, 'd') - } -} - -// StackTrace is stack of Frames from innermost (newest) to outermost (oldest). -type StackTrace []Frame - -func (st StackTrace) Format(s fmt.State, verb rune) { - switch verb { - case 'v': - switch { - case s.Flag('+'): - for _, f := range st { - fmt.Fprintf(s, "\n%+v", f) - } - case s.Flag('#'): - fmt.Fprintf(s, "%#v", []Frame(st)) - default: - fmt.Fprintf(s, "%v", []Frame(st)) - } - case 's': - fmt.Fprintf(s, "%s", []Frame(st)) - } -} - -// stack represents a stack of program counters. -type stack []uintptr - -func (s *stack) Format(st fmt.State, verb rune) { - switch verb { - case 'v': - switch { - case st.Flag('+'): - for _, pc := range *s { - f := Frame(pc) - fmt.Fprintf(st, "\n%+v", f) - } - } - } -} - -func (s *stack) StackTrace() StackTrace { - f := make([]Frame, len(*s)) - for i := 0; i < len(f); i++ { - f[i] = Frame((*s)[i]) - } - return f -} - -func callers() *stack { - const depth = 32 - var pcs [depth]uintptr - n := runtime.Callers(3, pcs[:]) - var st stack = pcs[0:n] - return &st -} - -// funcname removes the path prefix component of a function's name reported by func.Name(). -func funcname(name string) string { - i := strings.LastIndex(name, "/") - name = name[i+1:] - i = strings.Index(name, ".") - return name[i+1:] -} - -func trimGOPATH(name, file string) string { - // Here we want to get the source file path relative to the compile time - // GOPATH. As of Go 1.6.x there is no direct way to know the compiled - // GOPATH at runtime, but we can infer the number of path segments in the - // GOPATH. We note that fn.Name() returns the function name qualified by - // the import path, which does not include the GOPATH. Thus we can trim - // segments from the beginning of the file path until the number of path - // separators remaining is one more than the number of path separators in - // the function name. For example, given: - // - // GOPATH /home/user - // file /home/user/src/pkg/sub/file.go - // fn.Name() pkg/sub.Type.Method - // - // We want to produce: - // - // pkg/sub/file.go - // - // From this we can easily see that fn.Name() has one less path separator - // than our desired output. We count separators from the end of the file - // path until it finds two more than in the function name and then move - // one character forward to preserve the initial path segment without a - // leading separator. - const sep = "/" - goal := strings.Count(name, sep) + 2 - i := len(file) - for n := 0; n < goal; n++ { - i = strings.LastIndex(file[:i], sep) - if i == -1 { - // not enough separators found, set i so that the slice expression - // below leaves file unmodified - i = -len(sep) - break - } - } - // get back to 0 or trim the leading separator - file = file[i+len(sep):] - return file -} diff --git a/vendor/github.com/urfave/negroni/doc.go b/vendor/github.com/urfave/negroni/doc.go deleted file mode 100644 index add1ed9..0000000 --- a/vendor/github.com/urfave/negroni/doc.go +++ /dev/null @@ -1,25 +0,0 @@ -// Package negroni is an idiomatic approach to web middleware in Go. It is tiny, non-intrusive, and encourages use of net/http Handlers. -// -// If you like the idea of Martini, but you think it contains too much magic, then Negroni is a great fit. -// -// For a full guide visit http://github.com/urfave/negroni -// -// package main -// -// import ( -// "github.com/urfave/negroni" -// "net/http" -// "fmt" -// ) -// -// func main() { -// mux := http.NewServeMux() -// mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { -// fmt.Fprintf(w, "Welcome to the home page!") -// }) -// -// n := negroni.Classic() -// n.UseHandler(mux) -// n.Run(":3000") -// } -package negroni diff --git a/vendor/github.com/urfave/negroni/logger.go b/vendor/github.com/urfave/negroni/logger.go deleted file mode 100644 index 04cd53b..0000000 --- a/vendor/github.com/urfave/negroni/logger.go +++ /dev/null @@ -1,35 +0,0 @@ -package negroni - -import ( - "log" - "net/http" - "os" - "time" -) - -// ALogger interface -type ALogger interface { - Println(v ...interface{}) - Printf(format string, v ...interface{}) -} - -// Logger is a middleware handler that logs the request as it goes in and the response as it goes out. -type Logger struct { - // ALogger implements just enough log.Logger interface to be compatible with other implementations - ALogger -} - -// NewLogger returns a new Logger instance -func NewLogger() *Logger { - return &Logger{log.New(os.Stdout, "[negroni] ", 0)} -} - -func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - start := time.Now() - l.Printf("Started %s %s", r.Method, r.URL.Path) - - next(rw, r) - - res := rw.(ResponseWriter) - l.Printf("Completed %v %s in %v", res.Status(), http.StatusText(res.Status()), time.Since(start)) -} diff --git a/vendor/github.com/urfave/negroni/negroni.go b/vendor/github.com/urfave/negroni/negroni.go deleted file mode 100644 index 9c7c187..0000000 --- a/vendor/github.com/urfave/negroni/negroni.go +++ /dev/null @@ -1,133 +0,0 @@ -package negroni - -import ( - "log" - "net/http" - "os" -) - -// Handler handler is an interface that objects can implement to be registered to serve as middleware -// in the Negroni middleware stack. -// ServeHTTP should yield to the next middleware in the chain by invoking the next http.HandlerFunc -// passed in. -// -// If the Handler writes to the ResponseWriter, the next http.HandlerFunc should not be invoked. -type Handler interface { - ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) -} - -// HandlerFunc is an adapter to allow the use of ordinary functions as Negroni handlers. -// If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f. -type HandlerFunc func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) - -func (h HandlerFunc) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - h(rw, r, next) -} - -type middleware struct { - handler Handler - next *middleware -} - -func (m middleware) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - m.handler.ServeHTTP(rw, r, m.next.ServeHTTP) -} - -// Wrap converts a http.Handler into a negroni.Handler so it can be used as a Negroni -// middleware. The next http.HandlerFunc is automatically called after the Handler -// is executed. -func Wrap(handler http.Handler) Handler { - return HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - handler.ServeHTTP(rw, r) - next(rw, r) - }) -} - -// Negroni is a stack of Middleware Handlers that can be invoked as an http.Handler. -// Negroni middleware is evaluated in the order that they are added to the stack using -// the Use and UseHandler methods. -type Negroni struct { - middleware middleware - handlers []Handler -} - -// New returns a new Negroni instance with no middleware preconfigured. -func New(handlers ...Handler) *Negroni { - return &Negroni{ - handlers: handlers, - middleware: build(handlers), - } -} - -// Classic returns a new Negroni instance with the default middleware already -// in the stack. -// -// Recovery - Panic Recovery Middleware -// Logger - Request/Response Logging -// Static - Static File Serving -func Classic() *Negroni { - return New(NewRecovery(), NewLogger(), NewStatic(http.Dir("public"))) -} - -func (n *Negroni) ServeHTTP(rw http.ResponseWriter, r *http.Request) { - n.middleware.ServeHTTP(NewResponseWriter(rw), r) -} - -// Use adds a Handler onto the middleware stack. Handlers are invoked in the order they are added to a Negroni. -func (n *Negroni) Use(handler Handler) { - if handler == nil { - panic("handler cannot be nil") - } - - n.handlers = append(n.handlers, handler) - n.middleware = build(n.handlers) -} - -// UseFunc adds a Negroni-style handler function onto the middleware stack. -func (n *Negroni) UseFunc(handlerFunc func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)) { - n.Use(HandlerFunc(handlerFunc)) -} - -// UseHandler adds a http.Handler onto the middleware stack. Handlers are invoked in the order they are added to a Negroni. -func (n *Negroni) UseHandler(handler http.Handler) { - n.Use(Wrap(handler)) -} - -// UseHandler adds a http.HandlerFunc-style handler function onto the middleware stack. -func (n *Negroni) UseHandlerFunc(handlerFunc func(rw http.ResponseWriter, r *http.Request)) { - n.UseHandler(http.HandlerFunc(handlerFunc)) -} - -// Run is a convenience function that runs the negroni stack as an HTTP -// server. The addr string takes the same format as http.ListenAndServe. -func (n *Negroni) Run(addr string) { - l := log.New(os.Stdout, "[negroni] ", 0) - l.Printf("listening on %s", addr) - l.Fatal(http.ListenAndServe(addr, n)) -} - -// Returns a list of all the handlers in the current Negroni middleware chain. -func (n *Negroni) Handlers() []Handler { - return n.handlers -} - -func build(handlers []Handler) middleware { - var next middleware - - if len(handlers) == 0 { - return voidMiddleware() - } else if len(handlers) > 1 { - next = build(handlers[1:]) - } else { - next = voidMiddleware() - } - - return middleware{handlers[0], &next} -} - -func voidMiddleware() middleware { - return middleware{ - HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {}), - &middleware{}, - } -} diff --git a/vendor/github.com/urfave/negroni/recovery.go b/vendor/github.com/urfave/negroni/recovery.go deleted file mode 100644 index 8396cb1..0000000 --- a/vendor/github.com/urfave/negroni/recovery.go +++ /dev/null @@ -1,65 +0,0 @@ -package negroni - -import ( - "fmt" - "log" - "net/http" - "os" - "runtime" - "runtime/debug" -) - -// Recovery is a Negroni middleware that recovers from any panics and writes a 500 if there was one. -type Recovery struct { - Logger ALogger - PrintStack bool - ErrorHandlerFunc func(interface{}) - StackAll bool - StackSize int -} - -// NewRecovery returns a new instance of Recovery -func NewRecovery() *Recovery { - return &Recovery{ - Logger: log.New(os.Stdout, "[negroni] ", 0), - PrintStack: true, - StackAll: false, - StackSize: 1024 * 8, - } -} - -func (rec *Recovery) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - defer func() { - if err := recover(); err != nil { - if rw.Header().Get("Content-Type") == "" { - rw.Header().Set("Content-Type", "text/plain; charset=utf-8") - } - - rw.WriteHeader(http.StatusInternalServerError) - - stack := make([]byte, rec.StackSize) - stack = stack[:runtime.Stack(stack, rec.StackAll)] - - f := "PANIC: %s\n%s" - rec.Logger.Printf(f, err, stack) - - if rec.PrintStack { - fmt.Fprintf(rw, f, err, stack) - } - - if rec.ErrorHandlerFunc != nil { - func() { - defer func() { - if err := recover(); err != nil { - rec.Logger.Printf("provided ErrorHandlerFunc panic'd: %s, trace:\n%s", err, debug.Stack()) - rec.Logger.Printf("%s\n", debug.Stack()) - } - }() - rec.ErrorHandlerFunc(err) - }() - } - } - }() - - next(rw, r) -} diff --git a/vendor/github.com/urfave/negroni/response_writer.go b/vendor/github.com/urfave/negroni/response_writer.go deleted file mode 100644 index f805825..0000000 --- a/vendor/github.com/urfave/negroni/response_writer.go +++ /dev/null @@ -1,99 +0,0 @@ -package negroni - -import ( - "bufio" - "fmt" - "net" - "net/http" -) - -// ResponseWriter is a wrapper around http.ResponseWriter that provides extra information about -// the response. It is recommended that middleware handlers use this construct to wrap a responsewriter -// if the functionality calls for it. -type ResponseWriter interface { - http.ResponseWriter - http.Flusher - // Status returns the status code of the response or 200 if the response has - // not been written (as this is the default response code in net/http) - Status() int - // Written returns whether or not the ResponseWriter has been written. - Written() bool - // Size returns the size of the response body. - Size() int - // Before allows for a function to be called before the ResponseWriter has been written to. This is - // useful for setting headers or any other operations that must happen before a response has been written. - Before(func(ResponseWriter)) -} - -type beforeFunc func(ResponseWriter) - -// NewResponseWriter creates a ResponseWriter that wraps an http.ResponseWriter -func NewResponseWriter(rw http.ResponseWriter) ResponseWriter { - return &responseWriter{ - ResponseWriter: rw, - } -} - -type responseWriter struct { - http.ResponseWriter - status int - size int - beforeFuncs []beforeFunc -} - -func (rw *responseWriter) WriteHeader(s int) { - rw.status = s - rw.callBefore() - rw.ResponseWriter.WriteHeader(s) -} - -func (rw *responseWriter) Write(b []byte) (int, error) { - if !rw.Written() { - // The status will be StatusOK if WriteHeader has not been called yet - rw.WriteHeader(http.StatusOK) - } - size, err := rw.ResponseWriter.Write(b) - rw.size += size - return size, err -} - -func (rw *responseWriter) Status() int { - return rw.status -} - -func (rw *responseWriter) Size() int { - return rw.size -} - -func (rw *responseWriter) Written() bool { - return rw.status != 0 -} - -func (rw *responseWriter) Before(before func(ResponseWriter)) { - rw.beforeFuncs = append(rw.beforeFuncs, before) -} - -func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { - hijacker, ok := rw.ResponseWriter.(http.Hijacker) - if !ok { - return nil, nil, fmt.Errorf("the ResponseWriter doesn't support the Hijacker interface") - } - return hijacker.Hijack() -} - -func (rw *responseWriter) CloseNotify() <-chan bool { - return rw.ResponseWriter.(http.CloseNotifier).CloseNotify() -} - -func (rw *responseWriter) callBefore() { - for i := len(rw.beforeFuncs) - 1; i >= 0; i-- { - rw.beforeFuncs[i](rw) - } -} - -func (rw *responseWriter) Flush() { - flusher, ok := rw.ResponseWriter.(http.Flusher) - if ok { - flusher.Flush() - } -} diff --git a/vendor/github.com/urfave/negroni/static.go b/vendor/github.com/urfave/negroni/static.go deleted file mode 100644 index 34be967..0000000 --- a/vendor/github.com/urfave/negroni/static.go +++ /dev/null @@ -1,88 +0,0 @@ -package negroni - -import ( - "net/http" - "path" - "strings" -) - -// Static is a middleware handler that serves static files in the given -// directory/filesystem. If the file does not exist on the filesystem, it -// passes along to the next middleware in the chain. If you desire "fileserver" -// type behavior where it returns a 404 for unfound files, you should consider -// using http.FileServer from the Go stdlib. -type Static struct { - // Dir is the directory to serve static files from - Dir http.FileSystem - // Prefix is the optional prefix used to serve the static directory content - Prefix string - // IndexFile defines which file to serve as index if it exists. - IndexFile string -} - -// NewStatic returns a new instance of Static -func NewStatic(directory http.FileSystem) *Static { - return &Static{ - Dir: directory, - Prefix: "", - IndexFile: "index.html", - } -} - -func (s *Static) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { - if r.Method != "GET" && r.Method != "HEAD" { - next(rw, r) - return - } - file := r.URL.Path - // if we have a prefix, filter requests by stripping the prefix - if s.Prefix != "" { - if !strings.HasPrefix(file, s.Prefix) { - next(rw, r) - return - } - file = file[len(s.Prefix):] - if file != "" && file[0] != '/' { - next(rw, r) - return - } - } - f, err := s.Dir.Open(file) - if err != nil { - // discard the error? - next(rw, r) - return - } - defer f.Close() - - fi, err := f.Stat() - if err != nil { - next(rw, r) - return - } - - // try to serve index file - if fi.IsDir() { - // redirect if missing trailing slash - if !strings.HasSuffix(r.URL.Path, "/") { - http.Redirect(rw, r, r.URL.Path+"/", http.StatusFound) - return - } - - file = path.Join(file, s.IndexFile) - f, err = s.Dir.Open(file) - if err != nil { - next(rw, r) - return - } - defer f.Close() - - fi, err = f.Stat() - if err != nil || fi.IsDir() { - next(rw, r) - return - } - } - - http.ServeContent(rw, r, file, fi.ModTime(), f) -} -- cgit v1.2.3