Documentation ¶
Overview ¶
Package spartan_client provides an easy interface to create client and servers that speak the Spartan protocol.
It will automatically handle URLs that have IDNs in them, i.e. domains with Unicode. It will convert to punycode for DNS and for sending to the server, but accept certs with either punycode or Unicode as the hostname.
This also applies to hosts, for functions where a host can be passed specifically.
Index ¶
- Constants
- Variables
- func ContainsLetterRunes(s string) bool
- func CutAny(s string, chars string) (before string, after string, found bool)
- func GetPunycodeURL(u string) (string, error)
- func IsStatusValid(status int) bool
- func ParseLines(reader io.Reader, currentURLString string, lines *[]SpartanLine, ...) (string, bool)
- func QueryEscape(query string) string
- func QueryUnescape(query string) (string, error)
- func StatusInRange(status int) bool
- func StatusText(code int) string
- type Client
- type Error
- type ProxyFunc
- type Response
- type SpartanLine
- type SpartanLine_Heading
- type SpartanLine_Link
- type SpartanLine_OrderedListItem
- type SpartanLine_PreformattedText
- type SpartanLine_PreformattedToggle
- type SpartanLine_Quote
- type SpartanLine_Text
- type SpartanLine_UnorderedListItem
- type TextParsingState
Constants ¶
const ( URLMaxLength = 1024 MetaMaxLength = 1024 )
const ( StatusSuccess = 2 StatusRedirect = 3 ClientError = 4 ServerError = 5 )
Scroll status codes as defined in the Gemini spec Appendix 1.
Variables ¶
var DefaultClient = &Client{ConnectTimeout: 15 * time.Second}
var ISO8601Layout = "2006-01-02T15:04:05Z0700"
Functions ¶
func ContainsLetterRunes ¶
If the string contains any runes of the unicode L (Letter) category, excluding spaces
func CutAny ¶
CutAny slices s around any Unicode code point from chars, returning the text before and after it. The found result reports whether any Unicode code point was appears in s. If it does not appear in s, CutAny returns s, "", false.
func GetPunycodeURL ¶
GetPunycodeURL takes a full URL that potentially has Unicode in the domain name, and returns a URL with the domain punycoded.
func IsStatusValid ¶
IsStatusValid checks whether an int status is covered by the spec. Note that:
A client SHOULD deal with undefined status codes between '10' and '69' per the default action of the initial digit.
func ParseLines ¶
func ParseLines(reader io.Reader, currentURLString string, lines *[]SpartanLine, headings *[]SpartanLine_Heading, links *[]SpartanLine_Link) (string, bool)
func QueryEscape ¶
QueryEscape provides URL query escaping in a way that follows the Spartan spec. It is the same as url.PathEscape, but it also replaces the +, because Spartan requires percent-escaping for queries.
func QueryUnescape ¶
QueryUnescape is the same as url.PathUnescape
func StatusInRange ¶
StatusInRange returns true if the status has a valid first digit. This means it can be handled even if it's not defined by the spec, because it has a known category
func StatusText ¶
StatusText returns a text for the Scroll status code. It returns the empty string if the code is unknown.
Types ¶
type Client ¶
type Client struct { // AllowOutOfRangeStatuses means the client won't raise an error if a status // that is out of range is returned. // Use CleanStatus() to handle statuses that are in range but not specified in // the spec. AllowOutOfRangeStatuses bool // ConnectTimeout is equivalent to the Timeout field in net.Dialer. // It's the max amount of time allowed for the initial connection/handshake. // The timeout of the DefaultClient is 15 seconds. // // If ReadTimeout is not set, then this value is also used to time out on getting // the header after the connection is made. ConnectTimeout time.Duration // ReadTimeout is the max amount of time reading to a server can take. // This should not be set if you want to support streams. // It is equivalent to net.Conn.SetDeadline, see that func for more documentation. // // For example, if this is set to 30 seconds, then no more reading from the connection // can happen 30 seconds after the initial handshake. ReadTimeout time.Duration // Proxy is a function that returns an existing connection. The TLS client // will use this as the underlying transport, instead of making a direct TCP // connection. // // go-gemini requires setting a dialer on the underlying connection, to impose // a timeout on making the initial connection. This dialer is provided as an // argument to the proxy function. // // The other argument provided is the address being connected to. For example // "example.com:300". // // Any errors returned will prevent a connection from occurring. // // This is not "gemini proxying", aka the proxying functionality built in to // the Gemini protocol. This is for proxying requests over TOR, or SOCKS5, etc. // // func(dialer *net.Dialer, address string) (net.Conn, error) // Proxy ProxyFunc }
func (*Client) RequestWithHost ¶
Sends a message to a misfin server at the given host, with the given URL. This can be used for misfin proxying, where the URL host and actual server don't match. It assumes the host is using port 300 if no port number is provided.
type Response ¶
type Response struct { Status int Meta string // Input Prompt, Error Description, or Success Mimetype w/ Language Body io.ReadCloser // Use to get resource data (or abstract for metadata requests) // contains filtered or unexported fields }
Response represents the response from a Scroll server.
func RequestWithHost ¶
Sends a message to a misfin server at the given host, with the given URL. This can be used for misfin proxying, where the URL host and actual server don't match. It assumes the host is using port 300 if no port number is provided.
type SpartanLine ¶
type SpartanLine interface { String() string ImplementsScrollLine() }
type SpartanLine_Heading ¶
func (SpartanLine_Heading) ImplementsScrollLine ¶
func (heading SpartanLine_Heading) ImplementsScrollLine()
func (SpartanLine_Heading) String ¶
func (heading SpartanLine_Heading) String() string
type SpartanLine_Link ¶
type SpartanLine_Link struct { Url string Title string Relation int Tag string Input bool Time time.Time }
func (SpartanLine_Link) ImplementsScrollLine ¶
func (link SpartanLine_Link) ImplementsScrollLine()
func (SpartanLine_Link) String ¶
func (link SpartanLine_Link) String() string
type SpartanLine_OrderedListItem ¶
func (SpartanLine_OrderedListItem) ImplementsScrollLine ¶
func (listItem SpartanLine_OrderedListItem) ImplementsScrollLine()
func (SpartanLine_OrderedListItem) String ¶
func (listItem SpartanLine_OrderedListItem) String() string
type SpartanLine_PreformattedText ¶
type SpartanLine_PreformattedText string
func (SpartanLine_PreformattedText) ImplementsScrollLine ¶
func (preformattedText SpartanLine_PreformattedText) ImplementsScrollLine()
func (SpartanLine_PreformattedText) String ¶
func (preformattedText SpartanLine_PreformattedText) String() string
type SpartanLine_PreformattedToggle ¶
type SpartanLine_PreformattedToggle string
func (SpartanLine_PreformattedToggle) ImplementsScrollLine ¶
func (preformattedToggle SpartanLine_PreformattedToggle) ImplementsScrollLine()
func (SpartanLine_PreformattedToggle) String ¶
func (preformattedToggle SpartanLine_PreformattedToggle) String() string
type SpartanLine_Quote ¶
func (SpartanLine_Quote) ImplementsScrollLine ¶
func (quote SpartanLine_Quote) ImplementsScrollLine()
func (SpartanLine_Quote) String ¶
func (quote SpartanLine_Quote) String() string
type SpartanLine_Text ¶
type SpartanLine_Text string
func (SpartanLine_Text) ImplementsScrollLine ¶
func (text SpartanLine_Text) ImplementsScrollLine()
func (SpartanLine_Text) String ¶
func (text SpartanLine_Text) String() string
type SpartanLine_UnorderedListItem ¶
func (SpartanLine_UnorderedListItem) ImplementsScrollLine ¶
func (listItem SpartanLine_UnorderedListItem) ImplementsScrollLine()
func (SpartanLine_UnorderedListItem) String ¶
func (listItem SpartanLine_UnorderedListItem) String() string
type TextParsingState ¶
type TextParsingState struct {
// contains filtered or unexported fields
}