soap

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package soap provides transport-neutral SOAP 1.1 and SOAP 1.2 envelope, body, and fault primitives while preserving access to the original XML.

Index

Constants

View Source
const DefaultMaxBytes int64 = 1 << 20

DefaultMaxBytes is the default maximum SOAP envelope size.

Variables

View Source
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")

ErrPayloadTooLarge identifies SOAP output that exceeds the configured limit.

Functions

func Encode

func Encode(version Version, header, body any, options EncodeOptions) ([]byte, error)

Encode serializes typed header and body values as XML and wraps them in a SOAP envelope. A nil header is omitted and a nil body emits an empty Body.

func EncodeWriter

func EncodeWriter(writer io.Writer, version Version, header, body any, options EncodeOptions) error

EncodeWriter serializes typed SOAP values and writes the complete envelope to writer.

func Marshal

func Marshal(version Version, header, body []byte) ([]byte, error)

Marshal creates a deterministic SOAP envelope around validated raw header and body fragments.

func MarshalFault

func MarshalFault(fault Fault) ([]byte, error)

MarshalFault validates and serializes a SOAP fault envelope.

func MarshalFaultWithOptions

func MarshalFaultWithOptions(fault Fault, options MarshalOptions) ([]byte, error)

MarshalFaultWithOptions validates and serializes a size-bounded SOAP fault envelope.

func MarshalFaultWriter

func MarshalFaultWriter(writer io.Writer, fault Fault) error

MarshalFaultWriter serializes a SOAP fault and writes the complete envelope to writer.

func MarshalFaultWriterWithOptions

func MarshalFaultWriterWithOptions(writer io.Writer, fault Fault, options MarshalOptions) error

MarshalFaultWriterWithOptions serializes a size-bounded SOAP fault and writes it only after serialization succeeds.

func MarshalWithOptions

func MarshalWithOptions(version Version, header, body []byte, options MarshalOptions) ([]byte, error)

MarshalWithOptions creates a deterministic, size-bounded SOAP envelope around validated raw header and body fragments.

func MarshalWriter

func MarshalWriter(writer io.Writer, version Version, header, body []byte) error

MarshalWriter creates a SOAP envelope around raw fragments and writes it to writer.

func MarshalWriterWithOptions

func MarshalWriterWithOptions(writer io.Writer, version Version, header, body []byte, options MarshalOptions) error

MarshalWriterWithOptions creates a size-bounded SOAP envelope and writes it to writer only after serialization succeeds.

Types

type EncodeOptions

type EncodeOptions struct {
	MaxBytes int64
	Indent   string
}

EncodeOptions controls XML serialization for typed SOAP header and body values.

type Envelope

type Envelope struct {
	Version Version
	Fault   *Fault
	// contains filtered or unexported fields
}

Envelope is a validated SOAP envelope with preserved raw sections.

func Parse

func Parse(payload []byte, options ParseOptions) (*Envelope, error)

Parse validates and extracts a SOAP envelope. Valid SOAP faults return both the envelope and a *FaultError.

func ParseReader

func ParseReader(reader io.Reader, options ParseOptions) (*Envelope, error)

ParseReader reads a bounded stream and parses a SOAP envelope.

func (*Envelope) BodyXML

func (e *Envelope) BodyXML() []byte

BodyXML returns a copy of the exact XML inside the Body element.

func (*Envelope) DecodeBody

func (e *Envelope) DecodeBody(target any) error

DecodeBody decodes the single body child while retaining namespace bindings declared on the source envelope.

func (*Envelope) HeaderXML

func (e *Envelope) HeaderXML() []byte

HeaderXML returns a copy of the exact XML inside the Header element.

func (*Envelope) RawXML

func (e *Envelope) RawXML() []byte

RawXML returns a copy of the complete source envelope.

type Fault

type Fault struct {
	Version  Version
	Code     string
	Subcodes []string
	Reason   string
	Reasons  []FaultReason
	Actor    string
	Node     string
	Role     string
	Detail   []byte
	Raw      []byte
}

Fault is a version-neutral representation of SOAP 1.1 and 1.2 faults.

type FaultError

type FaultError struct {
	Fault Fault
}

FaultError reports a valid SOAP fault response.

func (*FaultError) Error

func (e *FaultError) Error() string

func (*FaultError) Unwrap

func (e *FaultError) Unwrap() error

Unwrap exposes the shared SOAP-fault classification.

type FaultReason

type FaultReason struct {
	Language string
	Text     string
}

FaultReason is one localized SOAP 1.2 fault reason.

type MarshalOptions

type MarshalOptions struct {
	MaxBytes int64
}

MarshalOptions controls raw SOAP envelope and fault serialization.

type ParseOptions

type ParseOptions struct {
	MaxBytes      int64
	MaxDepth      int
	CharsetReader func(string, io.Reader) (io.Reader, error)
}

ParseOptions controls SOAP envelope parsing.

type Version

type Version string

Version identifies a SOAP envelope namespace.

const (
	Version11 Version = "1.1"
	Version12 Version = "1.2"
)

Jump to

Keyboard shortcuts

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