Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyUA error = errors.New("empty user agent string") ErrIncompatFieldType error = errors.New("a field type was passed that is incompatible with the target type") ErrInvalidAccept error = errors.New("an Accept header was encountered that does not conform to RFC 9110§12.5.1/IANA format") ErrInvalidScheme error = errors.New("invalid scheme for listener; must be 'unix', 'tcp', or 'http'") ErrNoArgs error = errors.New("no args.Args passed to server creation") ErrPtrNeeded error = errors.New("structs passed to reflection must be pointers") ErrStructNeeded error = errors.New("pointers passed to reflection must point to structs") ErrUnhandledField error = errors.New("unhandled field type passed to reflection") ErrUnsupportedMIME error = errors.New("unsupported MIME type(s)") )
Functions ¶
This section is empty.
Types ¶
type Page ¶
type Page struct { Info *R00tInfo // e.g. "index.html.tpl"; populated by handler PageType string // Nil unless `?include=` specified, otherwise a block of text to be wrapped in <code>...</code>. Raw *string // RawFmt is the MIME type for Raw, if `?include=` enabled/specified. RawFmt *string // Indent specifies the indentation string. Indent string // DoIndent indicates if indenting was enabled. DoIndent bool }
Page is only used for HTML rendering.
type R00tClient ¶
type R00tClient struct { // XMLName is the element name/namespace of this object ("ua"). XMLName xml.Name `json:"-" xml:"ua" yaml:"-" uaField:"-" renderName:"-"` // String contains the entire UA string. String *string `json:"str,omitempty" xml:",chardata" yaml:"String"` // ClientVer is a parsed version structure of the client version (see ClientVerStr for the combined string). ClientVer *Ver `json:"ver,omitempty" xml:"version,omitempty" yaml:"Client Version,omitempty" uaField:"VersionNo" renderName:"-"` // OSVer is the parsed OS version info of the client (see OsVersionStr for the combined string). OSVer *Ver `` /* 128-byte string literal not displayed */ // URL, if any, is the URL of the client. URL *string `json:"url,omitempty" xml:"url,attr,omitempty" yaml:"URL,omitempty"` // Name is the client software name. Name *string `json:"name,omitempty" xml:"name,attr,omitempty" yaml:"Program/Name,omitempty"` // ClientVerStr contains the full version as a string (see also Clientversion). ClientVerStr *string `` /* 137-byte string literal not displayed */ // OS is the operating system of the client. OS *string `json:"os,omitempty" xml:"os,attr,omitempty" yaml:"Operating System,omitempty"` // OsVerStr is the version of the operating system of the client. OsVerStr *string `` /* 164-byte string literal not displayed */ // Dev is the device type. Dev *string `json:"dev,omitempty" xml:"dev,attr,omitempty" yaml:"Device,omitempty" uaField:"Device"` // IsMobile is true if this is a mobile device. IsMobile bool `json:"mobile" xml:"mobile,attr" yaml:"Is Mobile" uaField:"Mobile"` // sTablet is true if this is a tablet. IsTablet bool `json:"tablet" xml:"tablet,attr" yaml:"Is Tablet" uaField:"Tablet"` // IsDesktop is true if this is a desktop/laptop. IsDesktop bool `json:"desktop" xml:"desktop,attr" yaml:"Is Desktop" uaField:"Desktop"` // IsBot is true if this is a bot. IsBot bool `json:"bot" xml:"bot,attr" yaml:"Is Bot" uaField:"Bot"` // contains filtered or unexported fields }
R00tClient is the UA/Client info, if any passed by the client.
func NewClient ¶
func NewClient(uaStr string) (r *R00tClient, err error)
NewClient returns a R00tClient from a UA string.
func (*R00tClient) ToMap ¶
func (r *R00tClient) ToMap() (m map[string]string, err error)
ToMap generates and returns a map representation of a R00tClient.
Keys by default use the YAML tag for the name. If they are specified with the tag `renderName:"-"`, they are skipped. If they are specified with the tag `renderName:"Foo"`, the string "Foo" will be used as the key instead. Only bools, strings, and pointers thereof are allowed.
m will never be nil, but may be empty.
Currently err will always be nil but is specified for future API compatibility. It should be handled by callers for future-proofing, as it may not always be nil in the future.
type R00tInfo ¶
type R00tInfo struct { // XMLName is the element name/namespace of this object ("info"). XMLName xml.Name `json:"-" xml:"info" yaml:"-"` // Client is the UA/Client info, if any passed by the client. Client []*R00tClient `json:"ua,omitempty" xml:"ua,omitempty" yaml:"Client/User Agent,omitempty"` // IP is the client IP address. IP net.IP `json:"ip" xml:"ip,attr" yaml:"Client IP Address"` // Port is the client's port number. Port uint16 `json:"port" xml:"port,attr" yaml:"Client Port"` // Headers are the collection of the request headers sent by the client. Headers XmlHeaders `json:"headers" xml:"reqHeaders" yaml:"Request Headers"` // Req contains the original request. It is not rendered but may be used for templating. Req *http.Request `json:"-" xml:"-" yaml:"-"` }
R00tInfo is the structure of data returned to the client.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
NewServer returns a Server ready to use. Be sure to call Close to free up resources when done.
func (*Server) Close ¶
Close cleanly closes any remnants of a Server. Stop should be used instead to cleanly shut down; this is a little more aggressive.
func (*Server) Run ¶
Run starts and runs the server. This process blocks and will shutdown on a systemd notify signal or kill signal. Non-HTML requests will be of type R00tInfo serialized to the requested MIME type.
type Ver ¶
type XmlHeaders ¶
func (XmlHeaders) MarshalXML ¶
func (x XmlHeaders) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)
MarshalXML encodes an XmlHeaders as XML in the following format:
(<headers>)
<header name="SomeHeader"> <value>SomeValue</value> </header> <header name="SomeMultiValueHeader"> <value>Foo</value> <value>Bar</value> </header>
(</headers>)
For the above example, the field should be specified as `xml:"headers"`. However, the parent element name may be whatever you wish.
func (*XmlHeaders) UnmarshalXML ¶
func (x *XmlHeaders) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)
UnmarshalXML populates an XMLHeaders from an XML representation. See MarshalXML for example XML.