gopher

package module
v0.0.0-...-0a28f90 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 6 Imported by: 0

README

Gopher

GoDoc

A library to assit in creating gopher servers and (eventually) clients. This library is heavily inspired by the Go standard library's net/http with many design choices and concessions made to better support the gopher protocol.

Status

Currently, this project is in the early development stage and shouldn't even be considered alpha level software yet. None of the API should be considered stable. THIS IS NOT PRODUCTION READY.

Why?

Who doesn't want a Go powered gopher server?

Usage

TODO

License

Licensed under the terms of the MIT license. See LICENSE file for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(addr string, handler Handler) error

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 Item

type Item struct {
	Type     ItemType
	Display  string
	Selector string
	Hostname string
	Port     int

} //func

Item represents an item in a gopher menu.

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

const (
	ItemHTML    ItemType = 'h'
	ItemInfoMsg ItemType = 'i'
	ItemSound   ItemType = 's'
)

Non-canonical types

func CannonicalGuessItemType

func CannonicalGuessItemType(name string) ItemType

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

func GuessItemType(name string) ItemType

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 Menu []Item

Menu is a slice of Items.

type Muxer

type Muxer struct {
	// contains filtered or unexported fields

} //func

Muxer handles looks at the request and determines which Handler to call.

func NewMuxer

func NewMuxer() *Muxer

NewMuxer returns a new Muxer.

func (*Muxer) Handle

func (m *Muxer) Handle(path string, handler Handler)

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 Request

type Request struct {
	Path string
	Addr net.Addr

} //struct

Request contains data about a gopher client request.

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 (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.

func (*ResponseWriter) WriteText

func (w *ResponseWriter) WriteText(disp, sel, hname string, port int) error

WriteText writes a text link item.

type Server

type Server struct {
	Addr    string
	Handler Handler

} //struct

Server takes care of client connections.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the server listening and handling connections.

func (*Server) Serve

func (s *Server) Serve(listener net.Listener) error

Serve starts the server handling connections/requests with the provided listener.

Jump to

Keyboard shortcuts

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