gopher

package module
v0.0.0-...-7b034d2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2017 License: MIT Imports: 12 Imported by: 0

README

GoDoc

Loosely modeled after net/http.

Documentation

Index

Examples

Constants

View Source
const DefaultMaxReqBytes = 1 << 20 // 1 MB

DefaultMaxReqBytes is the maximum permitted size of a request. This can be overridden by setting Server.MaxReqBytes.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirEntry

type DirEntry struct {
	Type byte
	Name string
	Path string
	Host string
	Port string
}

A DirEntry represents a gopher directory entry.

type DirWriter

type DirWriter struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

A DirWriter is used to write gopher directories to a connection.

func (*DirWriter) Entry

func (dw *DirWriter) Entry(e *DirEntry) error

Entry writes a DirEntry to the current connection.

func (*DirWriter) LocalEntry

func (dw *DirWriter) LocalEntry(e *DirEntry) error

LocalEntry works like Entry but uses ExtHost and ExtPort from the server instead of the ones supplied in e.

type Handler

type Handler interface {
	ServeGopher(w *Writer, request *Request)
}

A Handler responds to a request.

func FileServer

func FileServer(root http.FileSystem) Handler

FileServer returns a handler that servers the contents of the file system rooted at root.

Example
srv := &gopher.Server{
	Addr:    "127.0.0.1:7070",
	ExtHost: "127.0.0.1",
	ExtPort: "7070",
	Handler: gopher.FileServer(http.Dir("/usr/share/doc")),
}
log.Fatal(srv.ListenAndServe())
Output:

type Request

type Request struct {
	RemoteAddr string // Network address that sent the request
	Content    []byte // Request contents
}

A Request represents a request received by a server.

type Server

type Server struct {
	Addr         string        // TCP address to listen on, ":7070" if empty
	ExtHost      string        // External address for this server (required for DirWriter.LocalEntry)
	ExtPort      string        // External port for this server (required for DirWriter.LocalEntry)
	Handler      Handler       // handler to invoke
	ReadTimeout  time.Duration // maximum duration before timing out read of the request
	WriteTimeout time.Duration // maximum duration before timing out write of the response
	MaxReqBytes  int           // maximum length for a request
	ErrorLog     *log.Logger   // optional logger for errors
}

A Server defines parameters for running a gopher server.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() error

ListenAndServe listens on the TCP network address srv.Addr and calls Serve to handle requests.

func (*Server) Serve

func (srv *Server) Serve(l net.Listener) error

Serve accepts incoming connections on the listener l, creating a new service goroutine for each. The service goroutines read a request and then call srv.Handler to reply to them.

type Writer

type Writer struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

A Writer is used for writing responses to requests.

func (*Writer) DirWriter

func (w *Writer) DirWriter() *DirWriter

DirWriter returns a DirWriter for a Writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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