gomini

package module
v0.0.0-...-a3e2661 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: ISC Imports: 10 Imported by: 1

README

gomini

yet another gemini client library

for the record, i started working on this a long time ago back when there weren't any go gemini libraries. it wasn't very good. it still isn't lmao but i rewrote it entirely

what?

godoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeMime

func DeMime(response []byte) ([]byte, error)

DeMime takes a Gemini response as a string and removes the mime header from it, returning what's left.

func Dial

func Dial(host string) (*tls.Conn, error)

Dial wraps tls.Dial to Dial a gemini server.

func LooksLikeLink(line string) bool

LooksLikeLink returns whether a line looks like it could be turned into a Link.

func LooksLikeRedirect

func LooksLikeRedirect(rawResponse []byte) bool

LooksLikeRedirect returns whether or not a raw response matches the format of a redirect.

func Respace

func Respace(line string) string

Respace returns a string with all whitespace nonsense that gemini.conman.org decides to throw my way torn out and replaced with spaces.

Types

type Index

type Index map[int]Link

Index is a set of Lines mapped to ints representing line numbers.

func (Index) At

func (ind Index) At(n int) (Link, error)

Index.At returns a link from a particular line, or an error if no link exists for that line.

func (Index) ByNumber

func (index Index) ByNumber(n int) (Link, error)

Index.ByNumber produces a link (or error) from an int representing the link number.

type Link struct {
	Description string
	Destination Request
}

Link holds a name and a gemini Request to represent a Gemini link line.

func ParseLink(s string, location Request) (Link, error)

ParseLink turns the string for a link into a Link with respect to a location.

func (Link) Follow

func (link Link) Follow(resp *Response) (Response, error)

Link.Follow returns a response and an error.

func (Link) String

func (link Link) String() string

Link.String() implements Stringer.

type Mime

type Mime struct {
	Type   string
	Params map[string]string
}

func GetMime

func GetMime(response []byte) (Mime, error)

GetMime takes a raw response from a server and returns its mime type as a string, along with mime params and possible errors along the way.

type Request

type Request struct {
	url.URL
}

Request extends url.URL to handle gemini requests, etc.

func BuildRequest

func BuildRequest(s string) (Request, error)

BuildRequest wraps url.Parse to parse a url string to produce a gemini Request.

func ParseRedirect

func ParseRedirect(rawResponse []byte) (Request, error)

ParseRedirect returns a request from a raw response.

func (Request) Get

func (req Request) Get() (Response, error)

Request.Get wraps Request.GetRaw to dial the server associated with a Request and produce a Response, handling redirects.

func (Request) GetRaw

func (req Request) GetRaw() ([]byte, error)

Request.GetRaw dials the server associated with a Request and returns a raw byte-slice response.

type Response

type Response struct {
	URL  Request
	Mime Mime
	Body []byte
}

Response contains the various parts of a response from a Gemini server.

func Fetch

func Fetch(uri string) (Response, error)

Fetch builds a request from a URI, then handles it and produces a Response; basically wraps all of this together more neatly.

func NewResponse

func NewResponse(rawResponse []byte) (Response, error)

NewResponse takes a server byte-slice response and produces a Response (sin Request).

func (resp Response) FollowLink(n int) (Response, error)

Response.FollowLink returns a Response from an int corresponding to a link number in the current Response.

func (Response) Index

func (resp Response) Index() Index

Response.Index() produces an Index from a Response.

func (Response) IsText

func (resp Response) IsText() bool

Response.IsText returns whether a response is a text type or not.

func (Response) LineBreak

func (resp Response) LineBreak() []string

Splits a Response body into lines at newline characters.

func (Response) String

func (resp Response) String() string

Response.String() implements Stringer. This isn't necessarily how you'll want to print it in a client implementation or something but it was good for debugging; w/e.

Jump to

Keyboard shortcuts

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