use within.website

This commit is contained in:
Cadey Ratio 2019-06-08 20:57:17 -04:00
parent 0c68ed5f58
commit cde46077a1
10 changed files with 27 additions and 57 deletions

View File

@ -3,8 +3,8 @@
[![Build Status](https://cloud.drone.io/api/badges/prologic/go-gopher/status.svg)](https://cloud.drone.io/prologic/go-gopher) [![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) [![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) [![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) [![GoDoc](https://godoc.org/within.website/gopher?status.svg)](https://godoc.org/within.website/gopher)
[![Sourcegraph](https://sourcegraph.com/github.com/prologic/go-gopher/-/badge.svg)](https://sourcegraph.com/github.com/prologic/go-gopher?badge) [![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 This is a standards compliant Gopher library for the Go programming language
implementing the RFC 1436 specification. The library includes both client and implementing the RFC 1436 specification. The library includes both client and
@ -13,13 +13,13 @@ server handling and examples of each.
## Installation ## Installation
```#!bash ```#!bash
$ go get github.com/prologic/go-gopher $ go get within.website/gopher
``` ```
## Usage ## Usage
```#!go ```#!go
import "github.com/prologic/go-gopher" import "within.website/gopher"
``` ```
## Example ## Example
@ -32,7 +32,7 @@ package main
import ( import (
"fmt" "fmt"
"github.com/prologic/go-gopher" "within.website/gopher"
) )
func main() { func main() {
@ -50,7 +50,7 @@ package main
import ( import (
"log" "log"
"github.com/prologic/go-gopher" "within.website/gopher"
) )
func hello(w gopher.ResponseWriter, r *gopher.Request) { func hello(w gopher.ResponseWriter, r *gopher.Request) {

View File

@ -1 +0,0 @@
theme: jekyll-theme-hacker

View File

@ -6,7 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"github.com/prologic/go-gopher" "within.website/gopher"
) )
var ( var (

View File

@ -5,7 +5,7 @@ import (
"log" "log"
"os" "os"
"github.com/prologic/go-gopher" "within.website/gopher"
) )
func cwd() string { func cwd() string {

Binary file not shown.

View File

@ -158,4 +158,4 @@ func main() {
pem.Encode(keyOut, pemBlockForKey(priv)) pem.Encode(keyOut, pemBlockForKey(priv))
keyOut.Close() keyOut.Close()
log.Print("written key.pem\n") log.Print("written key.pem\n")
} }

View File

@ -4,7 +4,7 @@ import (
"log" "log"
"sync" "sync"
"github.com/prologic/go-gopher" "within.website/gopher"
) )
func index(w gopher.ResponseWriter, r *gopher.Request) { func index(w gopher.ResponseWriter, r *gopher.Request) {

1
go.mod
View File

@ -5,4 +5,5 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2 github.com/stretchr/testify v1.2.2
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 golang.org/x/net v0.0.0-20181220203305-927f97764cc3
within.website/ln v0.6.0
) )

5
go.sum
View File

@ -1,8 +1,13 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 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/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 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 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 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=

View File

@ -10,6 +10,7 @@ package gopher
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"context"
"crypto/rand" "crypto/rand"
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
@ -27,8 +28,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"golang.org/x/net/context"
) )
// Item Types // Item Types
@ -210,27 +209,8 @@ func ParseItem(line string) (item *Item, err error) {
return 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 // MarshalText serializes an Item into an array of bytes
func (i *Item) MarshalText() ([]byte, error) { func (i Item) MarshalText() ([]byte, error) {
b := []byte{} b := []byte{}
b = append(b, byte(i.Type)) b = append(b, byte(i.Type))
b = append(b, []byte(i.Description)...) b = append(b, []byte(i.Description)...)
@ -251,7 +231,7 @@ func (i *Item) MarshalText() ([]byte, error) {
return b, nil return b, nil
} }
func (i *Item) isDirectoryLike() bool { func (i Item) isDirectoryLike() bool {
switch i.Type { switch i.Type {
case DIRECTORY: case DIRECTORY:
return true return true
@ -264,7 +244,7 @@ func (i *Item) isDirectoryLike() bool {
// Directory representes a Gopher Menu of Items // Directory representes a Gopher Menu of Items
type Directory struct { type Directory struct {
Items []*Item `json:"items"` Items []Item `json:"items"`
} }
// ToJSON returns the Directory as JSON bytes // ToJSON returns the Directory as JSON bytes
@ -409,7 +389,7 @@ func (i *Item) FetchDirectory() (Directory, error) {
scanner := bufio.NewScanner(reader) scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanLines) scanner.Split(bufio.ScanLines)
var items []*Item var items []Item
for scanner.Scan() { for scanner.Scan() {
line := strings.Trim(scanner.Text(), "\r\n") 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) log.Printf("Error parsing %q: %q", line, err)
continue continue
} }
items = append(items, item) items = append(items, *item)
} }
return Directory{items}, nil return Directory{items}, nil
@ -554,16 +534,9 @@ func GetItemType(p string) ItemType {
// Server defines parameters for running a Gopher server. // Server defines parameters for running a Gopher server.
// A zero value for Server is valid configuration. // A zero value for Server is valid configuration.
type Server struct { type Server struct {
Addr string // TCP address to listen on, ":gopher" if empty Addr string // TCP address to listen on, ":gopher" if empty
Handler Handler // handler to invoke, gopher.DefaultServeMux if nil Handler Handler // handler to invoke, gopher.DefaultServeMux if nil
Hostname string // FQDN Hostname to reach this server on
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
} }
// serverHandler delegates to either the server's Handler or // serverHandler delegates to either the server's Handler or
@ -646,7 +619,7 @@ func (s *Server) Serve(l net.Listener) error {
for { for {
rw, err := l.Accept() rw, err := l.Accept()
if err != nil { if err != nil {
fmt.Errorf("error acceptig new client: %s", err) fmt.Errorf("error accepting new client: %v", err)
return err return err
} }
@ -778,14 +751,6 @@ func (c *conn) readRequest(ctx context.Context) (w *response, err error) {
return w, nil 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 // ListenAndServe listens on the TCP network address addr
// and then calls Serve with handler to handle requests // and then calls Serve with handler to handle requests
// on incoming connections. // on incoming connections.
@ -798,7 +763,7 @@ func (s *Server) logf(format string, args ...interface{}) {
// "io" // "io"
// "log" // "log"
// //
// "github.com/prologic/go-gopher" // "within.website/gopher"
// ) // )
// //
// // hello world, the gopher server // // hello world, the gopher server