package module
v0.0.0-...-8ebb752 Latest Latest

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

Go to latest
Published: Nov 16, 2019 License: ISC Imports: 9 Imported by: 3


Go Gemini Library

go-gemini is a library that provide an easy interface to create client and servers that speak the Gemini protocol. The library is currently based on version 0.9.2 of the spec but will be updated accordingly to new changes in the protocol.

Example Server

The repository comes with an example server that respond with an hardcoded text to the root page. To build the server run the following command:

make build




View Source
const (
	StatusInput = 10

	StatusSuccess                              = 20
	StatusSuccessEndOfClientCertificateSession = 21

	StatusRedirect          = 30
	StatusRedirectTemporary = 30
	StatusRedirectPermanent = 31

	StatusTemporaryFailure = 40
	StatusUnavailable      = 41
	StatusCGIError         = 42
	StatusProxyError       = 43
	StatusSlowDown         = 44

	StatusPermanentFailure    = 50
	StatusNotFound            = 51
	StatusGone                = 52
	StatusProxyRequestRefused = 53
	StatusBadRequest          = 59

	StatusClientCertificateRequired     = 60
	StatusTransientCertificateRequested = 61
	StatusAuthorisedCertificateRequired = 62
	StatusCertificateNotAccepted        = 63
	StatusFutureCertificateRejected     = 64
	StatusExpiredCertificateRejected    = 65

Gemini status codes as defined in the Gemini spec Appendix 1.


View Source
var DefaultClient = &Client{}


func ListenAndServe

func ListenAndServe(addr, certFile, keyFile string, handler Handler) error

ListenAndServe create a TCP server on the specified address and pass new connections to the given handler. Each request is handled in a separate goroutine.

func SimplifyStatus

func SimplifyStatus(status int) int

SimplifyStatus simplify the response status by omiting the detailed second digit of the status code.


type Client

type Client struct {
	InsecureSkipVerify bool

func (Client) Fetch

func (c Client) Fetch(url string) (res Response, err error)

Fetch a resource from a Gemini server with the given URL

type Error

type Error struct {
	Err    error
	Status int

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type Handler

type Handler interface {
	Handle(r Request) Response

Handler is the interface a struct need to implement to be able to handle Gemini requests

type Request

type Request struct {
	URL string

Request contains the data of the client request

type Response

type Response struct {
	Status int
	Meta   string
	Body   io.ReadCloser

Response represent the response from a Gemini server.

func ErrorResponse

func ErrorResponse(err error) Response

ErrorResponse create a response from the given error with the error string as the Meta field. If the error is of type gemini.Error, the status will be taken from the status field, otherwise it will default to StatusTemporaryFailure. If the error is nil, the function will panic.

func Fetch

func Fetch(url string) (res Response, err error)

Fetch a resource from a Gemini server with the default client


Path Synopsis

Jump to

Keyboard shortcuts

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