internal

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHost is the default host to use for the server.
	DefaultHost = "127.0.0.1"
	// DefaultPort is the default port to use for the server. We choose 0 so that
	// an ephemeral port is selected by the OS if no port is specified.
	DefaultPort = 0
	// The fully-qualified service name for the Conformance Service.
	ConformanceServiceName = conformancev1connect.ConformanceServiceName
	// The prefix for type URLs used in Any messages.
	DefaultAnyResolverPrefix = "type.googleapis.com/"
)
View Source
const (
	ClientCertName = "Conformance Client"
	ServerCertName = "Conformance Server"
)

Variables

View Source
var (

	// Version is the version to report from all binaries.
	Version = buildVersion + buildVersionSuffix
)

Functions

func AddHeaders

func AddHeaders(
	src []*conformancev1.Header,
	dest http.Header,
)

AddHeaders adds all header values in src to dest.

func AddTrailers

func AddTrailers(
	src []*conformancev1.Header,
	dest http.Header,
)

AddTrailers adds all header values in src to dest, but it prefixes each header name with http.TrailerPrefix.

func ConvertConnectToProtoError

func ConvertConnectToProtoError(err *connect.Error) *conformancev1.Error

ConvertConnectToProtoError converts the given Connect error to a proto Error message. If err is nil, the function will also return nil.

func ConvertErrorToConnectError

func ConvertErrorToConnectError(err error) *connect.Error

ConvertErrorToConnectError converts the given error to a Connect error If err is nil, function will also return nil. If err is not of type connect.Error, a Connect error of code Unknown is returned.

func ConvertErrorToProtoError

func ConvertErrorToProtoError(err error) *conformancev1.Error

ConvertErrorToProtoError converts the given error to a proto Error If err is nil, function will also return nil. If err is not of type connect.Error, a code representing Unknown is returned.

func ConvertProtoToConnectError

func ConvertProtoToConnectError(err *conformancev1.Error) *connect.Error

ConvertProtoToConnectError creates a Connect error from the given proto Error message.

func ConvertToProtoHeader

func ConvertToProtoHeader(src map[string][]string) []*conformancev1.Header

ConvertToProtoHeader converts a map to a slice of proto Headers. Note that this can accept types of url.Values and http.Header.

func EnsureFileName

func EnsureFileName(err error, filename string) error

EnsureFileName ensures that the given error includes the given filename. If it does not, it wraps the error in one that does include the filename. This is used to ensure that file-system-specific errors have good messages and unambiguously indicate which file was the cause of the error.

func NewClientCert

func NewClientCert() (certBytes, keyBytes []byte, err error)

NewClientCert is like NewServerCert, but it produces a certificate that is intended for client authentication.

func NewClientTLSConfig

func NewClientTLSConfig(caCert, clientCert, clientKey []byte) (*tls.Config, error)

NewClientTLSConfig returns a TLS configuration for an RPC client that uses the given PEM-encoded certs/keys. The caCert parameter must not be empty, and is the server certificate to trust (or a CA cert for the issuer of the server cert). The clientCert and clientKey parameters are optional. If one is provided then both must be present. They enable the use of a client certificate during the TLS handshake, for mutually-authenticated TLS.

func NewServerCert

func NewServerCert() (certBytes, keyBytes []byte, err error)

NewServerCert generates a new self-signed certificate. The first return value is usable with a *tls.Config. The next two values are the PEM-encoded certificate (which must be shared with clients for them to trust the server) and key (which should not be shared). All three will be zero values if the returned error is not nil.

func NewServerTLSConfig

func NewServerTLSConfig(cert tls.Certificate, clientCertMode tls.ClientAuthType, clientCACert []byte) (*tls.Config, error)

NewServerTLSConfig returns a TLS configuration for an RPC server that uses the given PEM-encoded cert/key. If the cert and key parameters are required. The clientCACert parameter is required unless clientCerts is tls.NoClientCert.

func ParseServerCert

func ParseServerCert(cert, key []byte) (tls.Certificate, error)

ParseServerCert parses the given PEM-encoded cert and key.

func ReadDelimitedMessage

func ReadDelimitedMessage[T proto.Message](in io.Reader, msg T, source string, timeout time.Duration, maxSize int) error

ReadDelimitedMessage reads the next message from in. This first reads a fixed four byte preface, which is a network-encoded (i.e. big-endian) 32-bit integer that represents the message size. This then reads a number of bytes equal to that size and unmarshals it into msg.

func WriteDelimitedMessage

func WriteDelimitedMessage[T proto.Message](out io.Writer, msg T) error

WriteDelimitedMessage writes msg to out in a way that can be read by ReadDelimitedMessage.

func WriteRawMessageContents

func WriteRawMessageContents(contents *conformancev1.MessageContents, writer io.Writer) error

WriteRawMessageContents writes the given message contents to the given writer.

func WriteRawStreamContents

func WriteRawStreamContents(contents *conformancev1.StreamContents, writer io.Writer) error

WriteRawStreamContents writes the given stream contents to the given writer.

Types

type CancelTiming

type CancelTiming struct {
	BeforeCloseSend   *emptypb.Empty
	AfterCloseSendMs  int
	AfterNumResponses int
}

func GetCancelTiming

func GetCancelTiming(cancel *conformancev1.ClientCompatRequest_Cancel) (*CancelTiming, error)

GetCancelTiming evaluates a Cancel setting and returns a struct with the appropriate value set.

type Codec

type Codec interface {
	NewDecoder(io.Reader) StreamDecoder
	NewEncoder(io.Writer) StreamEncoder
}

Codec describes anything that can marshal and unmarshal proto messages.

func NewCodec

func NewCodec(json bool) Codec

NewCodec returns a new Codec.

type Printer

type Printer interface {
	// Printf formats the given message and arguments. A newline
	// is automatically added, so it is not necessary to include
	// an explicit "\n" at the end.
	Printf(msg string, args ...any)
	// PrefixPrintf is just like Printf except it will print
	// the given prefix followed by ": " before printing the
	// messages and arguments.
	PrefixPrintf(prefix, msg string, args ...any)
}

Printer is a simple interface for formatting human-readable messages.

func NewPrinter

func NewPrinter(w io.Writer) Printer

NewPrinter returns a thread-safe printer that prints messages to the given writer. The returned printer may safely be used from concurrent goroutines, even if the given writer is not safe for concurrent use.

type SimplePrinter

type SimplePrinter struct {
	Messages []string
}

SimplePrinter is a non-thread-safe printer that stores the printed messages in a slice.

func (*SimplePrinter) PrefixPrintf

func (l *SimplePrinter) PrefixPrintf(prefix, msg string, args ...any)

func (*SimplePrinter) Printf

func (l *SimplePrinter) Printf(msg string, args ...any)

type StreamDecoder

type StreamDecoder interface {
	DecodeNext(msg proto.Message) error
}

StreamDecoder is used to decode messages from a stream. This is used when the input contains a sequence of messages, not just one.

type StreamEncoder

type StreamEncoder interface {
	Encode(msg proto.Message) error
}

StreamEncoder is used to encode messages to a stream. This is used when the output will contain a sequence of messages, not just one.

type TextConnectCodec

type TextConnectCodec struct {
	prototext.MarshalOptions
	prototext.UnmarshalOptions
}

TextConnectCodec implements the connect.Codec interface, providing the protobuf text format.

func (*TextConnectCodec) Marshal

func (t *TextConnectCodec) Marshal(a any) ([]byte, error)

func (*TextConnectCodec) Name

func (t *TextConnectCodec) Name() string

func (*TextConnectCodec) Unmarshal

func (t *TextConnectCodec) Unmarshal(bytes []byte, a any) error

Directories

Path Synopsis
app
connectconformance/testsuites
Package testsuites contains embedded test suite data used when running conformance tests.
Package testsuites contains embedded test suite data used when running conformance tests.
gen

Jump to

Keyboard shortcuts

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