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 DirWriter ¶
type DirWriter struct { io.WriteCloser // contains filtered or unexported fields }
A DirWriter is used to write gopher directories to a connection.
func (*DirWriter) LocalEntry ¶
LocalEntry works like Entry but uses ExtHost and ExtPort from the server instead of the ones supplied in e.
type Handler ¶
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 ¶
ListenAndServe listens on the TCP network address srv.Addr and calls Serve to handle requests.
Click to show internal directories.
Click to hide internal directories.