Documentation ¶
Index ¶
- func ListenAndServe(addr string, handler Handler) error
- type Handler
- type HandlerFunc
- type Item
- type ItemType
- type Menu
- type Muxer
- type Request
- type ResponseWriter
- func (w *ResponseWriter) Done() (err error)
- func (w *ResponseWriter) RawItem(kind byte, disp, sel, hname string, port int) (err error)
- func (w *ResponseWriter) Write(data []byte) (int, error)
- func (w *ResponseWriter) WriteBin(disp, sel, hname string, port int) error
- func (w *ResponseWriter) WriteError(msg string) error
- func (w *ResponseWriter) WriteInfo(msg string) error
- func (w *ResponseWriter) WriteItem(i Item) error
- func (w *ResponseWriter) WriteLink(disp, sel, hname string, port int) error
- func (w *ResponseWriter) WriteMenu(m Menu) (err error)
- func (w *ResponseWriter) WriteText(disp, sel, hname string, port int) error
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe is a conveince methods to quickly setup a Server and start handling requests.
Types ¶
type Handler ¶
type Handler interface { Serve(writer *ResponseWriter, request *Request) } //interface
Handler is something that can handle a client connection.
type HandlerFunc ¶
type HandlerFunc func(*ResponseWriter, *Request)
HandlerFunc is a function that implements Handler.
func (HandlerFunc) Serve ¶
func (h HandlerFunc) Serve(w *ResponseWriter, r *Request)
Serve the connection by using the HandlerFunc.
type ItemType ¶
type ItemType byte
ItemType represents a menu item type for the Gopher protocol.
const ( ItemText ItemType = '0' ItemSubMenu ItemType = '1' ItemCCSONameserver ItemType = '2' ItemError ItemType = '3' ItemBinHexEnc ItemType = '4' ItemDOSFile ItemType = '5' ItemUuencoded ItemType = '6' ItemFullTextSearch ItemType = '7' ItemTelnet ItemType = '8' ItemBinary ItemType = '9' ItemMirror ItemType = '+' ItemGIF ItemType = 'g' ItemImage ItemType = 'I' )
Canonical types
Non-canonical types
func CannonicalGuessItemType ¶
CannonicalGuessItemType will attempt to deduce the ItemType by looking at the provided name. It follows the same rules as GuessItemType but will return ItemBinary for HTML and sound/audio files.
func GuessItemType ¶
GuessItemType will attempt to deduce the ItemType by looking at the provided filename. Non-canonical types are included. For Canonical only types use CannonicalGuessItemType. The rules are as follows:
If the file ends in .txt it is assumed to be a text file. If it ends in .gif it is a GIF. Files ending in .png, .jp(e)?g, ,.svg, .tiff are assumed to be image files. If the file ends in .html it is assumed to be a HTML file. Files ending with .wav, .mp3, .aac, .flac, .ogg are assumed to be sound files.
type Muxer ¶
type Muxer struct { // contains filtered or unexported fields } //func
Muxer handles looks at the request and determines which Handler to call.
func (*Muxer) Handle ¶
Handle adds a new Handler for the path to the Muxer. If a previous Handler existed for the path it is forgotten.
func (*Muxer) Serve ¶
func (m *Muxer) Serve(w *ResponseWriter, r *Request)
Serve the client with some Handler.
type ResponseWriter ¶
type ResponseWriter struct { // contains filtered or unexported fields } //struct
ResponseWriter provides functionality to write to a Gopher client. It provides somme convenience methods for writing "menu items".
func (*ResponseWriter) Done ¶
func (w *ResponseWriter) Done() (err error)
Done will send a full stop (".") on a line all to itself. A "good" gopher server will write a full stop before disconnecting the client. However, most clients seem to be able to deal with a missing full-stop. Thus calling Done is probably optional (but recommended).
func (*ResponseWriter) RawItem ¶
func (w *ResponseWriter) RawItem(kind byte, disp, sel, hname string, port int) (err error)
RawItem is a method that does a raw write of an item withough any checking. Use other methods for specific (known) types.
func (*ResponseWriter) Write ¶
func (w *ResponseWriter) Write(data []byte) (int, error)
Write data to the ResponseWriter.
func (*ResponseWriter) WriteBin ¶
func (w *ResponseWriter) WriteBin(disp, sel, hname string, port int) error
WriteBin writes a binary link item.
func (*ResponseWriter) WriteError ¶
func (w *ResponseWriter) WriteError(msg string) error
WriteError writes an error line.
func (*ResponseWriter) WriteInfo ¶
func (w *ResponseWriter) WriteInfo(msg string) error
WriteInfo writes an info line.
func (*ResponseWriter) WriteItem ¶
func (w *ResponseWriter) WriteItem(i Item) error
WriteItem writes an Item from a Menu.
func (*ResponseWriter) WriteLink ¶
func (w *ResponseWriter) WriteLink(disp, sel, hname string, port int) error
WriteLink writes a link to gopher submenu.
func (*ResponseWriter) WriteMenu ¶
func (w *ResponseWriter) WriteMenu(m Menu) (err error)
WriteMenu writes a Menu.
type Server ¶
Server takes care of client connections.
func (*Server) ListenAndServe ¶
ListenAndServe starts the server listening and handling connections.