Documentation
¶
Index ¶
- Constants
- Variables
- func Call(w WaaTargetParam, ctx WaaCtx) (error, bool)
- 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 WaaCtx
- type WaaRouter
- func (r *WaaRouter) AddTarget(name string, host string, port int, timeouts ...int) (error, *WaaTarget)
- func (r *WaaRouter) GetTargetIndexByName(name string) int
- func (w *WaaRouter) GetWaaTargetParam(ctx WaaCtx) (error, *WaaTarget)
- func (r *WaaRouter) MapPackageToTarget(pkgName string, targetName string) error
- func (r *WaaRouter) SetDefaultTarget(name string) error
- func (r *WaaRouter) SetPackageVarName(name string)
- type WaaTarget
- type WaaTargetParam
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 ¶
var ErrInvalidTargetName = errors.New("invalid target name")
ErrInvalidTargetName is AddTarget refusing the reserved name "!".
var ErrNoWaaTargetConfigured = errors.New("no WAA target configured")
ErrNoWaaTargetConfigured means the destination resolved to nothing at all: no target was ever configured.
var ErrShouldBeDispatchedElsewhere = errors.New("should be dispatched elsewhere")
ErrShouldBeDispatchedElsewhere means this request is not WAA's: the package is mapped to "!" or no default target exists. Elsewhere is anything that is not WAA — typically the package's replacement in another technology, but whatever the caller decides. Call answers it with dispatched == false.
var ErrTargetIndexOutOfRange = errors.New("target index out of range")
ErrTargetIndexOutOfRange means a package mapping points past the target list — a router wired by hand into an inconsistent state.
var ErrTargetNameAlreadyExists = errors.New("target name already exists")
ErrTargetNameAlreadyExists is AddTarget refusing a duplicate name.
var ErrTargetNameNotFound = errors.New("target name not found")
ErrTargetNameNotFound means no target carries the requested name.
Functions ¶
func Call ¶ added in v0.1.1
func Call(w WaaTargetParam, ctx WaaCtx) (error, bool)
Call resolves the destination through w, dials it, runs one complete conversation against ctx and closes the connection — not persistent: one call, one connection, gone when the call returns.
The second result says whether the request was dispatched to WAA at all: false means nobody was dialed (e.g. the router answered ErrShouldBeDispatchedElsewhere) and the request belongs outside WAA — typically a package already migrated to another technology, but whatever the caller decides: it should serve the request itself.
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 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.
type WaaRouter ¶ added in v0.1.1
type WaaRouter struct {
// contains filtered or unexported fields
}
WaaRouter is the multibinding destination: it holds several targets and picks one per call by the package variable of the conversation (WAA_PACKAGE by default). Unmapped packages go to the default target (the first one added, unless SetDefaultTarget says otherwise), and a package mapped to "!" is served elsewhere — anything that is not WAA: the call answers ErrShouldBeDispatchedElsewhere and the caller serves it its own way. The typical use is the migration lever: an Xbase++/WAA program moves to Go package by package, each replacement mapped to "!", WAA serving the rest, no seams visible.
func (*WaaRouter) AddTarget ¶ added in v0.1.1
func (r *WaaRouter) AddTarget(name string, host string, port int, timeouts ...int) (error, *WaaTarget)
AddTarget registers one WAA server under a name ("" auto-names it "host:port"; "!" is reserved and refused) and returns the created target. The first target added is the default one. Timeouts are optional: conn, read, write, in seconds.
func (*WaaRouter) GetTargetIndexByName ¶ added in v0.1.1
GetTargetIndexByName finds a target by its name, case-insensitively; -1 when no target carries it.
func (*WaaRouter) GetWaaTargetParam ¶ added in v0.1.1
GetWaaTargetParam resolves the destination for this conversation: the package variable is asked to the ctx, mapped packages go to their target, unmapped ones to the default, and no default (or a "!" mapping) answers ErrShouldBeDispatchedElsewhere — not WAA's request.
func (*WaaRouter) MapPackageToTarget ¶ added in v0.1.1
MapPackageToTarget binds one package value to a target by name. Target "!" marks the package as already migrated: it will be dispatched elsewhere (the migration lever, one package at a time).
func (*WaaRouter) SetDefaultTarget ¶ added in v0.1.1
SetDefaultTarget picks the target that serves the unmapped packages. "!" means no default at all: anything unmapped should be dispatched elsewhere.
func (*WaaRouter) SetPackageVarName ¶ added in v0.1.1
SetPackageVarName changes the variable that picks the binding. Usually you migrate package by package (WAA_PACKAGE, the default), but inside one package another variable may play the pivot; "" resets to the default.
type WaaTarget ¶ added in v0.1.1
type WaaTarget 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
Name string // optional name for this target, used in a router
// contains filtered or unexported fields
}
WaaTarget holds how to reach a WAA server: host, port, timeouts.
func (*WaaTarget) GetWaaTargetParam ¶ added in v0.1.1
GetWaaTargetParam satisfies WaaTargetParam by answering itself: a WaaTarget IS its own destination, whatever the conversation carries.
type WaaTargetParam ¶ added in v0.1.1
WaaTargetParam is the virtual destination of a call: given the conversation context it answers WHICH server to dial. A WaaTarget answers itself; a WaaRouter picks by the package variable; anything else may implement its own policy.