gemini

package module
v0.0.0-...-85f011a Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 7 Imported by: 0

README

gemini

A small go module to serve Gemini servers, create requests, etc.

Installation

go get github.com/CPunch/gemini

Example

package main

import (
	"github.com/CPunch/gemini"
)

func main() {
	response, _ := gemini.LazyRequest("gemini://gemini.circumlunar.space/docs/specification.gmi")

	println(response)
}

More examples (including servers!) can be found in the /examples directory

Documentation

Index

Constants

View Source
const (
	StatusInput              = 10
	StatusSuccess            = 20
	StatusRedirect           = 30
	StatusRedirectTemp       = 30
	StatusRedirectPerm       = 31
	StatusTemporaryFailure   = 40
	StatusUnavailable        = 41
	StatusPermanentFailure   = 50
	StatusNotFound           = 51
	StatusBadRequest         = 59
	StatusClientCertRequired = 60
)

Variables

This section is empty.

Functions

func LazyRequest

func LazyRequest(url string) (result string, err error)

func NewHandler

func NewHandler() *pathHandler

func ParseURL

func ParseURL(rawUrl string) (uri, hostname, path, param string)

(can panic !)

Types

type GeminiBody

type GeminiBody struct {
	// contains filtered or unexported fields
}

func NewBody

func NewBody() *GeminiBody

func (*GeminiBody) AddHeader

func (body *GeminiBody) AddHeader(str string)

func (*GeminiBody) AddLinkLine

func (body *GeminiBody) AddLinkLine(url, text string)

func (*GeminiBody) AddRaw

func (body *GeminiBody) AddRaw(data string)

func (*GeminiBody) AddTextLine

func (body *GeminiBody) AddTextLine(str string)

type GeminiPeer

type GeminiPeer struct {
	// contains filtered or unexported fields
}

func (*GeminiPeer) GetAddr

func (peer *GeminiPeer) GetAddr() string

func (*GeminiPeer) GetParam

func (peer *GeminiPeer) GetParam() (string, bool)

returns (param, isParam). if isParam is false, the peer did not post any parameter data

func (*GeminiPeer) Kill

func (peer *GeminiPeer) Kill()

func (*GeminiPeer) Read

func (peer *GeminiPeer) Read(p []byte) int

returns number of bytes read into p (can panic!)

func (*GeminiPeer) SendBody

func (peer *GeminiPeer) SendBody(body *GeminiBody)

sends a StatusSuccess response header and the body (can panic !)

func (*GeminiPeer) SendError

func (peer *GeminiPeer) SendError(meta string)

meta is the text that is reported to the user (can panic !)

func (*GeminiPeer) SendInput

func (peer *GeminiPeer) SendInput(meta string)

meta is the text that is prompted for the user (can panic !)

func (*GeminiPeer) Write

func (peer *GeminiPeer) Write(p []byte)

writes bytes to tls connection (can panic !)

type GeminiRequest

type GeminiRequest struct {
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(uri, hostname, port, path, param string) (req *GeminiRequest, err error)

make a gemini request

func (*GeminiRequest) Read

func (req *GeminiRequest) Read(p []byte) int

simple wrapper to read raw data over the tls connection

func (*GeminiRequest) Write

func (req *GeminiRequest) Write(p []byte)

simple wrapper to write raw data over the tls connection (can panic !)

type GeminiServer

type GeminiServer struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(port, certFile, keyFile string) (*GeminiServer, error)

func (*GeminiServer) Run

func (server *GeminiServer) Run(peerRequest func(peer *GeminiPeer))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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