summaryrefslogtreecommitdiff
path: root/gopher
diff options
context:
space:
mode:
Diffstat (limited to 'gopher')
-rw-r--r--gopher/client.go10
-rw-r--r--gopher/request.go6
-rw-r--r--gopher/response.go70
-rw-r--r--gopher/serve.go10
4 files changed, 48 insertions, 48 deletions
diff --git a/gopher/client.go b/gopher/client.go
index 163d0cd..5ef54ff 100644
--- a/gopher/client.go
+++ b/gopher/client.go
@@ -7,7 +7,7 @@ import (
"net"
neturl "net/url"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
)
// Client is used for sending gopher requests and producing the responses.
@@ -18,7 +18,7 @@ import (
type Client struct{}
// RoundTrip sends a single gopher request and returns its response.
-func (c Client) RoundTrip(request *sr.Request) (*sr.Response, error) {
+func (c Client) RoundTrip(request *types.Request) (*types.Response, error) {
if request.Scheme != "gopher" && request.Scheme != "" {
return nil, errors.New("non-gopher protocols not supported")
}
@@ -52,14 +52,14 @@ func (c Client) RoundTrip(request *sr.Request) (*sr.Response, error) {
return nil, err
}
- return &sr.Response{Body: bytes.NewBuffer(response)}, nil
+ return &types.Response{Body: bytes.NewBuffer(response)}, nil
}
// Fetch parses a URL string and fetches the gopher resource.
-func (c Client) Fetch(url string) (*sr.Response, error) {
+func (c Client) Fetch(url string) (*types.Response, error) {
u, err := neturl.Parse(url)
if err != nil {
return nil, err
}
- return c.RoundTrip(&sr.Request{URL: u})
+ return c.RoundTrip(&types.Request{URL: u})
}
diff --git a/gopher/request.go b/gopher/request.go
index 4aac218..eef8262 100644
--- a/gopher/request.go
+++ b/gopher/request.go
@@ -8,11 +8,11 @@ import (
"path"
"strings"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
)
// ParseRequest parses a gopher protocol request into a sliderule.Request object.
-func ParseRequest(rdr io.Reader) (*sr.Request, error) {
+func ParseRequest(rdr io.Reader) (*types.Request, error) {
selector, search, err := readFullRequest(rdr)
if err != nil {
return nil, err
@@ -22,7 +22,7 @@ func ParseRequest(rdr io.Reader) (*sr.Request, error) {
selector = "/" + selector
}
- return &sr.Request{
+ return &types.Request{
URL: &url.URL{
Scheme: "gopher",
Path: path.Clean(selector),
diff --git a/gopher/response.go b/gopher/response.go
index 566623f..527e742 100644
--- a/gopher/response.go
+++ b/gopher/response.go
@@ -6,49 +6,49 @@ import (
"io"
"sync"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
)
// The Canonical gopher item types.
const (
- TextFileType sr.Status = '0'
- MenuType sr.Status = '1'
- CSOPhoneBookType sr.Status = '2'
- ErrorType sr.Status = '3'
- MacBinHexType sr.Status = '4'
- DosBinType sr.Status = '5'
- UuencodedType sr.Status = '6'
- SearchType sr.Status = '7'
- TelnetSessionType sr.Status = '8'
- BinaryFileType sr.Status = '9'
- MirrorServerType sr.Status = '+'
- GifFileType sr.Status = 'g'
- ImageFileType sr.Status = 'I'
- Telnet3270Type sr.Status = 'T'
+ TextFileType types.Status = '0'
+ MenuType types.Status = '1'
+ CSOPhoneBookType types.Status = '2'
+ ErrorType types.Status = '3'
+ MacBinHexType types.Status = '4'
+ DosBinType types.Status = '5'
+ UuencodedType types.Status = '6'
+ SearchType types.Status = '7'
+ TelnetSessionType types.Status = '8'
+ BinaryFileType types.Status = '9'
+ MirrorServerType types.Status = '+'
+ GifFileType types.Status = 'g'
+ ImageFileType types.Status = 'I'
+ Telnet3270Type types.Status = 'T'
)
// The gopher+ types.
const (
- BitmapType sr.Status = ':'
- MovieFileType sr.Status = ';'
- SoundFileType sr.Status = '<'
+ BitmapType types.Status = ':'
+ MovieFileType types.Status = ';'
+ SoundFileType types.Status = '<'
)
// The various non-canonical gopher types.
const (
- DocumentType sr.Status = 'd'
- HTMLType sr.Status = 'h'
- InfoMessageType sr.Status = 'i'
- PngImageFileType sr.Status = 'p'
- RtfDocumentType sr.Status = 'r'
- WavSoundFileType sr.Status = 's'
- PdfDocumentType sr.Status = 'P'
- XmlDocumentType sr.Status = 'X'
+ DocumentType types.Status = 'd'
+ HTMLType types.Status = 'h'
+ InfoMessageType types.Status = 'i'
+ PngImageFileType types.Status = 'p'
+ RtfDocumentType types.Status = 'r'
+ WavSoundFileType types.Status = 's'
+ PdfDocumentType types.Status = 'P'
+ XmlDocumentType types.Status = 'X'
)
// MapItem is a single item in a gophermap.
type MapItem struct {
- Type sr.Status
+ Type types.Status
Display string
Selector string
Hostname string
@@ -70,8 +70,8 @@ func (mi MapItem) String() string {
// Response builds a response which contains just this single MapItem.
//
// Meta in the response will be a pointer to the MapItem.
-func (mi *MapItem) Response() *sr.Response {
- return &sr.Response{
+func (mi *MapItem) Response() *types.Response {
+ return &types.Response{
Status: mi.Type,
Meta: &mi,
Body: bytes.NewBufferString(mi.String() + ".\r\n"),
@@ -89,8 +89,8 @@ func (md MapDocument) String() string {
// Response builds a gopher response containing the gophermap.
//
// Meta will be the MapDocument itself.
-func (md MapDocument) Response() *sr.Response {
- return &sr.Response{
+func (md MapDocument) Response() *types.Response {
+ return &types.Response{
Status: DocumentType,
Meta: md,
Body: md.serialize(),
@@ -119,12 +119,12 @@ func Error(err error) *MapItem {
// File builds a minimal response delivering a file's contents.
//
// Meta is nil and Status is 0 in this response.
-func File(status sr.Status, contents io.Reader) *sr.Response {
- return &sr.Response{Status: status, Body: contents}
+func File(status types.Status, contents io.Reader) *types.Response {
+ return &types.Response{Status: status, Body: contents}
}
// NewResponseReader produces a reader which supports reading gopher protocol responses.
-func NewResponseReader(response *sr.Response) sr.ResponseReader {
+func NewResponseReader(response *types.Response) types.ResponseReader {
return &responseReader{
Response: response,
once: &sync.Once{},
@@ -132,7 +132,7 @@ func NewResponseReader(response *sr.Response) sr.ResponseReader {
}
type responseReader struct {
- *sr.Response
+ *types.Response
reader io.Reader
once *sync.Once
}
diff --git a/gopher/serve.go b/gopher/serve.go
index 7b32f2f..56b38f6 100644
--- a/gopher/serve.go
+++ b/gopher/serve.go
@@ -7,14 +7,14 @@ import (
"io"
"net"
- sr "tildegit.org/tjp/sliderule"
+ "tildegit.org/tjp/sliderule/internal/types"
"tildegit.org/tjp/sliderule/internal"
"tildegit.org/tjp/sliderule/logging"
)
type gopherServer struct {
internal.Server
- handler sr.Handler
+ handler types.Handler
}
func (gs gopherServer) Protocol() string { return "GOPHER" }
@@ -25,9 +25,9 @@ func NewServer(
hostname string,
network string,
address string,
- handler sr.Handler,
+ handler types.Handler,
errLog logging.Logger,
-) (sr.Server, error) {
+) (types.Server, error) {
gs := &gopherServer{handler: handler}
hostname = internal.JoinDefaultPort(hostname, "70")
@@ -43,7 +43,7 @@ func NewServer(
}
func (gs *gopherServer) handleConn(conn net.Conn) {
- var response *sr.Response
+ var response *types.Response
request, err := ParseRequest(conn)
if err != nil {
response = Error(errors.New("Malformed request.")).Response()