diff --git a/README.md b/README.md index e19ed48..73792a3 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [![Build Status](https://cloud.drone.io/api/badges/prologic/go-gopher/status.svg)](https://cloud.drone.io/prologic/go-gopher) [![CodeCov](https://codecov.io/gh/prologic/go-gopher/branch/master/graph/badge.svg)](https://codecov.io/gh/prologic/go-gopher) [![Go Report Card](https://goreportcard.com/badge/prologic/go-gopher)](https://goreportcard.com/report/prologic/go-gopher) -[![GoDoc](https://godoc.org/github.com/prologic/go-gopher?status.svg)](https://godoc.org/github.com/prologic/go-gopher) -[![Sourcegraph](https://sourcegraph.com/github.com/prologic/go-gopher/-/badge.svg)](https://sourcegraph.com/github.com/prologic/go-gopher?badge) +[![GoDoc](https://godoc.org/within.website/gopher?status.svg)](https://godoc.org/within.website/gopher) +[![Sourcegraph](https://sourcegraph.com/within.website/gopher/-/badge.svg)](https://sourcegraph.com/within.website/gopher?badge) This is a standards compliant Gopher library for the Go programming language implementing the RFC 1436 specification. The library includes both client and @@ -13,13 +13,13 @@ server handling and examples of each. ## Installation ```#!bash -$ go get github.com/prologic/go-gopher +$ go get within.website/gopher ``` ## Usage ```#!go -import "github.com/prologic/go-gopher" +import "within.website/gopher" ``` ## Example @@ -32,7 +32,7 @@ package main import ( "fmt" - "github.com/prologic/go-gopher" + "within.website/gopher" ) func main() { @@ -50,7 +50,7 @@ package main import ( "log" - "github.com/prologic/go-gopher" + "within.website/gopher" ) func hello(w gopher.ResponseWriter, r *gopher.Request) { diff --git a/_config.yml b/_config.yml deleted file mode 100644 index fc24e7a..0000000 --- a/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-hacker \ No newline at end of file diff --git a/examples/client/main.go b/examples/client/main.go index 7b69242..6992acd 100644 --- a/examples/client/main.go +++ b/examples/client/main.go @@ -6,7 +6,7 @@ import ( "io/ioutil" "log" - "github.com/prologic/go-gopher" + "within.website/gopher" ) var ( diff --git a/examples/fileserver/main.go b/examples/fileserver/main.go index 2e371dc..5227691 100644 --- a/examples/fileserver/main.go +++ b/examples/fileserver/main.go @@ -5,7 +5,7 @@ import ( "log" "os" - "github.com/prologic/go-gopher" + "within.website/gopher" ) func cwd() string { diff --git a/examples/hello/gencerts b/examples/hello/gencerts deleted file mode 100755 index b38a7e5..0000000 Binary files a/examples/hello/gencerts and /dev/null differ diff --git a/examples/hello/gencerts.go b/examples/hello/gencerts.go index 05ada27..83f9916 100644 --- a/examples/hello/gencerts.go +++ b/examples/hello/gencerts.go @@ -158,4 +158,4 @@ func main() { pem.Encode(keyOut, pemBlockForKey(priv)) keyOut.Close() log.Print("written key.pem\n") -} \ No newline at end of file +} diff --git a/examples/hello/main.go b/examples/hello/main.go index 869ee63..1d646dd 100644 --- a/examples/hello/main.go +++ b/examples/hello/main.go @@ -4,7 +4,7 @@ import ( "log" "sync" - "github.com/prologic/go-gopher" + "within.website/gopher" ) func index(w gopher.ResponseWriter, r *gopher.Request) { diff --git a/go.mod b/go.mod index e986f99..8ee0fd4 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,5 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.2 golang.org/x/net v0.0.0-20181220203305-927f97764cc3 + within.website/ln v0.6.0 ) diff --git a/go.sum b/go.sum index 75bee2d..42c267e 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +within.website/ln v0.6.0 h1:zn8vE9f0biSTNIpHFc7kOPH+SitLsWrU1MfrwMSS4cM= +within.website/ln v0.6.0/go.mod h1:ifURKqsCJekcsdUE+hyCdcuhQqQ+9v9DfA++ZqYxZFE= diff --git a/gopher.go b/gopher.go index bf6a491..7bfe4c1 100644 --- a/gopher.go +++ b/gopher.go @@ -10,6 +10,7 @@ package gopher import ( "bufio" "bytes" + "context" "crypto/rand" "crypto/tls" "encoding/json" @@ -27,8 +28,6 @@ import ( "strconv" "strings" "sync" - - "golang.org/x/net/context" ) // Item Types @@ -210,27 +209,8 @@ func ParseItem(line string) (item *Item, err error) { return } -// MarshalJSON serializes an Item into a JSON structure -func (i *Item) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string `json:"type"` - Description string `json:"description"` - Selector string `json:"selector"` - Host string `json:"host"` - Port int `json:"port"` - Extras []string `json:"extras"` - }{ - Type: string(i.Type), - Description: i.Description, - Selector: i.Selector, - Host: i.Host, - Port: i.Port, - Extras: i.Extras, - }) -} - // MarshalText serializes an Item into an array of bytes -func (i *Item) MarshalText() ([]byte, error) { +func (i Item) MarshalText() ([]byte, error) { b := []byte{} b = append(b, byte(i.Type)) b = append(b, []byte(i.Description)...) @@ -251,7 +231,7 @@ func (i *Item) MarshalText() ([]byte, error) { return b, nil } -func (i *Item) isDirectoryLike() bool { +func (i Item) isDirectoryLike() bool { switch i.Type { case DIRECTORY: return true @@ -264,7 +244,7 @@ func (i *Item) isDirectoryLike() bool { // Directory representes a Gopher Menu of Items type Directory struct { - Items []*Item `json:"items"` + Items []Item `json:"items"` } // ToJSON returns the Directory as JSON bytes @@ -409,7 +389,7 @@ func (i *Item) FetchDirectory() (Directory, error) { scanner := bufio.NewScanner(reader) scanner.Split(bufio.ScanLines) - var items []*Item + var items []Item for scanner.Scan() { line := strings.Trim(scanner.Text(), "\r\n") @@ -427,7 +407,7 @@ func (i *Item) FetchDirectory() (Directory, error) { log.Printf("Error parsing %q: %q", line, err) continue } - items = append(items, item) + items = append(items, *item) } return Directory{items}, nil @@ -554,16 +534,9 @@ func GetItemType(p string) ItemType { // Server defines parameters for running a Gopher server. // A zero value for Server is valid configuration. type Server struct { - Addr string // TCP address to listen on, ":gopher" if empty - Handler Handler // handler to invoke, gopher.DefaultServeMux if nil - - Hostname string // FQDN Hostname to reach this server on - - // ErrorLog specifies an optional logger for errors accepting - // connections and unexpected behavior from handlers. - // If nil, logging goes to os.Stderr via the log package's - // standard logger. - ErrorLog *log.Logger + Addr string // TCP address to listen on, ":gopher" if empty + Handler Handler // handler to invoke, gopher.DefaultServeMux if nil + Hostname string // FQDN Hostname to reach this server on } // serverHandler delegates to either the server's Handler or @@ -646,7 +619,7 @@ func (s *Server) Serve(l net.Listener) error { for { rw, err := l.Accept() if err != nil { - fmt.Errorf("error acceptig new client: %s", err) + fmt.Errorf("error accepting new client: %v", err) return err } @@ -778,14 +751,6 @@ func (c *conn) readRequest(ctx context.Context) (w *response, err error) { return w, nil } -func (s *Server) logf(format string, args ...interface{}) { - if s.ErrorLog != nil { - s.ErrorLog.Printf(format, args...) - } else { - log.Printf(format, args...) - } -} - // ListenAndServe listens on the TCP network address addr // and then calls Serve with handler to handle requests // on incoming connections. @@ -798,7 +763,7 @@ func (s *Server) logf(format string, args ...interface{}) { // "io" // "log" // -// "github.com/prologic/go-gopher" +// "within.website/gopher" // ) // // // hello world, the gopher server