Documentation
¶
Index ¶
- Constants
- func PutMessage(conn io.Writer, cmd int32, data []byte) error
- func PutMessageString(conn io.Writer, cmd int32, data string) error
- type DirectWaaCtx
- func (c *DirectWaaCtx) AddValue(name, value string)
- func (c *DirectWaaCtx) OnEmail(rfc822data []byte) error
- func (c *DirectWaaCtx) OnGetAllVars() []KvEntry
- func (c *DirectWaaCtx) OnGetEnv(name string) string
- func (c *DirectWaaCtx) OnGetVar(name string) ([]string, bool)
- func (c *DirectWaaCtx) OnHeaderLine(line string, lineTerminator int) error
- func (c *DirectWaaCtx) OnOpenFile(filename string) (io.WriteCloser, error)
- func (c *DirectWaaCtx) OnPutData(data []byte) error
- func (c *DirectWaaCtx) SetMethod(method string)
- func (c *DirectWaaCtx) SetValue(name, value string)
- func (c *DirectWaaCtx) SetValues(name string, values []string)
- type KvEntry
- type Message
- type NullWaaCtx
- func (NullWaaCtx) OnEmail(rfc822data []byte) error
- func (NullWaaCtx) OnEndHeader(lineTerminator int) error
- func (NullWaaCtx) OnGetAllVars() []KvEntry
- func (NullWaaCtx) OnGetDocRoot() string
- func (NullWaaCtx) OnGetEnv(name string) string
- func (NullWaaCtx) OnGetScriptName() string
- func (NullWaaCtx) OnGetVar(name string) ([]string, bool)
- func (NullWaaCtx) OnHeaderLine(line string, lineTerminator int) error
- func (NullWaaCtx) OnOpenFile(filename string) (io.WriteCloser, error)
- func (NullWaaCtx) OnPutData(data []byte) error
- type WaaClient
- type WaaCtx
Constants ¶
const ( CmdConnect int32 = 0 // First connection from the gateway CmdDisconnect int32 = 1 // Last command from the server CmdReady int32 = 2 // Server ready CmdAck int32 = 3 // Positive acknowledgement CmdNak int32 = 4 // Negative acknowledgement CmdGetEnv int32 = 100 // Get environment variable CmdPutEnv int32 = 110 // Response to GetEnv CmdGetVar int32 = 200 // Get form variable CmdPutVar int32 = 210 // Response to GetVar CmdPut int32 = 201 // Write HTML output CmdGetAllVars int32 = 300 // Get all variables CmdPutAllVars int32 = 310 // Response to GetAllVars CmdOpenFile int32 = 400 // Open file for writing CmdPutFileData int32 = 401 // Write data to file CmdCloseFile int32 = 402 // Close file CmdGetDocRoot int32 = 500 // Get document root CmdGetScriptName int32 = 600 // Get script name CmdEmail int32 = 700 // Send email )
CGI protocol commands
const ( EolLf = int(linereader.EolLf) EolCr = int(linereader.EolCr) EolCrLf = int(linereader.EolCrLf) )
Line terminators reported to OnHeaderLine and OnEndHeader; the values are linereader's EolType.
Variables ¶
This section is empty.
Functions ¶
func PutMessage ¶
PutMessage sends a message to the WAA transport Format: <msgLen 4 bytes><cmd 4 bytes><data>
Types ¶
type DirectWaaCtx ¶
type DirectWaaCtx struct {
NullWaaCtx
// Env answers OnGetEnv verbatim (CGI names, e.g. "SERVER_NAME").
// REQUEST_METHOD defaults to "POST" when not set.
Env map[string]string
// Header collects the CGI header lines emitted by the application,
// one entry per line, without terminators.
Header []string
// Body collects the application output after the header separator —
// or all of it, when the application never emitted a separator.
Body []byte
// Files collects the files sent by the application, name -> content.
Files map[string]*bytes.Buffer
// Emails collects the email messages requested by the application,
// raw and in order of arrival.
Emails [][]byte
// contains filtered or unexported fields
}
DirectWaaCtx is a WaaCtx you fill by hand: direct data in, output collected in memory to read after the call. It does not perform the call itself — pass it to WaaClient.Call. A DirectWaaCtx belongs to one conversation: do not share a live one between concurrent calls.
func NewDirectWaaCtx ¶
func NewDirectWaaCtx(env map[string]string) *DirectWaaCtx
NewDirectWaaCtx returns a DirectWaaCtx ready to fill. env may be nil (empty environment).
func (*DirectWaaCtx) AddValue ¶
func (c *DirectWaaCtx) AddValue(name, value string)
AddValue adds one more value to a form variable, creating it if it does not exist.
func (*DirectWaaCtx) OnEmail ¶
func (c *DirectWaaCtx) OnEmail(rfc822data []byte) error
func (*DirectWaaCtx) OnGetAllVars ¶
func (c *DirectWaaCtx) OnGetAllVars() []KvEntry
func (*DirectWaaCtx) OnGetEnv ¶
func (c *DirectWaaCtx) OnGetEnv(name string) string
func (*DirectWaaCtx) OnHeaderLine ¶
func (c *DirectWaaCtx) OnHeaderLine(line string, lineTerminator int) error
func (*DirectWaaCtx) OnOpenFile ¶
func (c *DirectWaaCtx) OnOpenFile(filename string) (io.WriteCloser, error)
func (*DirectWaaCtx) OnPutData ¶
func (c *DirectWaaCtx) OnPutData(data []byte) error
func (*DirectWaaCtx) SetMethod ¶
func (c *DirectWaaCtx) SetMethod(method string)
SetMethod sets the REQUEST_METHOD environment variable.
func (*DirectWaaCtx) SetValue ¶
func (c *DirectWaaCtx) SetValue(name, value string)
SetValue sets a form variable to a single value, replacing whatever it had.
func (*DirectWaaCtx) SetValues ¶
func (c *DirectWaaCtx) SetValues(name string, values []string)
SetValues sets a form variable to the given values, replacing whatever it had. The variable keeps the name case of its first appearance.
type KvEntry ¶
KvEntry is one form variable with its collected values, in order of first appearance.
type Message ¶
Message represents a WAA protocol message
func GetMessage ¶
GetMessage reads a message from the WAA transport Format: <msgLen 4 bytes><cmd 4 bytes><data>
func (*Message) DataString ¶
DataString returns the message data as a string
type NullWaaCtx ¶
type NullWaaCtx struct{}
NullWaaCtx is a do-nothing WaaCtx: empty answers, discarded output, files and email rejected (NAK). Embed it to implement only the methods you need.
func (NullWaaCtx) OnEmail ¶
func (NullWaaCtx) OnEmail(rfc822data []byte) error
func (NullWaaCtx) OnEndHeader ¶
func (NullWaaCtx) OnEndHeader(lineTerminator int) error
func (NullWaaCtx) OnGetAllVars ¶
func (NullWaaCtx) OnGetAllVars() []KvEntry
func (NullWaaCtx) OnGetDocRoot ¶
func (NullWaaCtx) OnGetDocRoot() string
func (NullWaaCtx) OnGetEnv ¶
func (NullWaaCtx) OnGetEnv(name string) string
func (NullWaaCtx) OnGetScriptName ¶
func (NullWaaCtx) OnGetScriptName() string
func (NullWaaCtx) OnHeaderLine ¶
func (NullWaaCtx) OnHeaderLine(line string, lineTerminator int) error
func (NullWaaCtx) OnOpenFile ¶
func (NullWaaCtx) OnOpenFile(filename string) (io.WriteCloser, error)
func (NullWaaCtx) OnPutData ¶
func (NullWaaCtx) OnPutData(data []byte) error
type WaaClient ¶
type WaaClient struct {
Host string // default 127.0.0.1
Port int // default 1024
// Timeouts in seconds
ConnTimeout int // default 30
ReadTimeout int // default 60
WriteTimeout int // default 60
}
WaaClient holds how to reach a WAA server: host, port, timeouts. It keeps no live state — each Call opens its own connection — so one WaaClient is safe for any number of concurrent calls, each with its own WaaCtx.
type WaaCtx ¶
type WaaCtx interface {
// OnGetEnv answers CmdGetEnv: the value of an environment variable,
// empty if unknown.
OnGetEnv(name string) string
// OnGetVar answers CmdGetVar: the decoded values of a form variable
// (a form key may repeat), and whether it exists. The protocol
// answer carries the first value.
OnGetVar(name string) ([]string, bool)
// OnGetAllVars answers CmdGetAllVars: all form variables in order of
// first appearance, each with its collected values (a form key may
// repeat). The protocol answer carries them URL-encoded.
OnGetAllVars() []KvEntry
// OnGetDocRoot answers CmdGetDocRoot.
OnGetDocRoot() string
// OnGetScriptName answers CmdGetScriptName.
OnGetScriptName() string
// OnHeaderLine receives one CGI header line emitted by the WAA
// application, without its terminator; lineTerminator is one of the
// Eol* constants. Returning an error aborts the conversation.
OnHeaderLine(line string, lineTerminator int) error
// OnEndHeader signals the empty line that closes the header block,
// with its terminator. Returning an error aborts the conversation.
OnEndHeader(lineTerminator int) error
// OnPutData receives the application output that follows the header
// block — the body. If the application never emits a header
// separator, all its output arrives here at the end of the
// conversation. Returning an error aborts the conversation.
OnPutData(data []byte) error
// OnOpenFile returns the destination stream for a file sent by the WAA
// server. The loop writes the received data to it and closes it when
// the server closes the file. Error or nil writer = NAK.
OnOpenFile(filename string) (io.WriteCloser, error)
// OnEmail sends an email message, passed through untouched as received
// from the WAA server. Error = NAK.
OnEmail(rfc822data []byte) error
}
WaaCtx is what one WAA conversation talks to. It is fully virtual: only methods, no data. The protocol loop (Run) translates each server command into a method call, so implementations decide where the data comes from and where the output goes — an HTTP request, a plain Go call, a test, anything.