Documentation
¶
Index ¶
- Constants
- func CreateAuthenticationOKMessage() []byte
- func CreateStartupMessage(version int32, username string, database string, options map[string]string) []byte
- func HandleAuthenticationRequest(username string, password string, connection net.Conn) (err error)
- func NewError(data []byte) error
- func ParseStartupMessage(message []byte) (version int32, options map[string]string, err error)
- func ReadMessage(client io.Reader) (messageType byte, message []byte, err error)
- func ReadStartupMessage(client io.Reader) ([]byte, error)
- type Error
- type MessageBuffer
- func (message *MessageBuffer) Bytes() []byte
- func (message *MessageBuffer) ReadByte() (byte, error)
- func (message *MessageBuffer) ReadInt32() (value int32, err error)
- func (message *MessageBuffer) ReadString() (string, error)
- func (message *MessageBuffer) ResetLength(offset int)
- func (message *MessageBuffer) WriteByte(value byte) error
- func (message *MessageBuffer) WriteInt32(value int32) (err error)
- func (message *MessageBuffer) WriteString(value string) (int, error)
Constants ¶
const ( ErrorSeverityFatal string = "FATAL" ErrorSeverityPanic string = "PANIC" ErrorSeverityWarning string = "WARNING" ErrorSeverityNotice string = "NOTICE" ErrorSeverityDebug string = "DEBUG" ErrorSeverityInfo string = "INFO" ErrorSeverityLog string = "LOG" )
PG Error Severity Levels
const ( ErrorFieldSeverity byte = 'S' ErrorFieldCode byte = 'C' ErrorFieldMessage byte = 'M' ErrorFieldMessageDetail byte = 'D' ErrorFieldMessageHint byte = 'H' )
PG Error Message Field Identifiers
const ( PGMessageLengthOffsetStartup int = 0 PGMessageLengthOffset int = 1 )
PostgreSQL message length offset constants.
const ( ProtocolVersion int32 = 196608 SSLRequestCode int32 = 80877103 /* SSL Responses */ SSLAllowed byte = 'S' SSLNotAllowed byte = 'N' )
PostgreSQL Protocol Version/Code constants
const ( AuthenticationMessageType byte = 'R' ErrorMessageType byte = 'E' EmptyQueryMessageType byte = 'I' DescribeMessageType byte = 'D' RowDescriptionMessageType byte = 'T' DataRowMessageType byte = 'D' QueryMessageType byte = 'Q' CommandCompleteMessageType byte = 'C' TerminateMessageType byte = 'X' NoticeMessageType byte = 'N' PasswordMessageType byte = 'p' ReadyForQueryMessageType byte = 'Z' )
PostgreSQL Message Type constants.
const ( AuthenticationOk int32 = 0 AuthenticationKerberosV5 int32 = 2 AuthenticationClearText int32 = 3 AuthenticationMD5 int32 = 5 AuthenticationSCM int32 = 6 AuthenticationGSS int32 = 7 AuthenticationGSSContinue int32 = 8 AuthenticationSSPI int32 = 9 )
PostgreSQL Authentication Method constants.
const (
// ErrorCodeInternalError indicates an unspecified internal error.
ErrorCodeInternalError = "XX000"
)
Variables ¶
This section is empty.
Functions ¶
func CreateAuthenticationOKMessage ¶
func CreateAuthenticationOKMessage() []byte
CreateAuthenticationOKMessage creates a Postgresql message which indicates successful authentication.
func CreateStartupMessage ¶
func CreateStartupMessage( version int32, username string, database string, options map[string]string, ) []byte
CreateStartupMessage creates a PG startup message. This message is used to startup all connections with a PG backend.
func HandleAuthenticationRequest ¶
HandleAuthenticationRequest sends credentials to the server and reports whether they were accepted or not.
func NewError ¶ added in v1.3.0
NewError constructs a protocol error from an error packet. This is done, instead of passing the error through to the client as is, to give Secretless the ability to modify the error contents.
NewError parses the error packet and populates the protocol error with the field types as detailed in the protocol documentation: https://www.postgresql.org/docs/9.1/protocol-error-fields.html. If parsing fails NewError returns an "unparseable error from postgres server" error.
NOTE: We have made a conscious choice to propagate a subset of the error field types. We focus on those that are always present and, by our assessment, hold the most salient information.
func ParseStartupMessage ¶
ParseStartupMessage parses the pg startup message.
func ReadMessage ¶
ReadMessage accepts an incoming message. The first byte is the message type, the second int32 is the message length, and the rest of the bytes are the message body.
Types ¶
type MessageBuffer ¶
type MessageBuffer struct {
// contains filtered or unexported fields
}
MessageBuffer is a variable-sized byte buffer used to read and write PostgreSQL Frontend and Backend messages.
A separate instance of a MessageBuffer should be use for reading and writing.
func NewMessageBuffer ¶
func NewMessageBuffer(message []byte) *MessageBuffer
NewMessageBuffer creates and intializes a new MessageBuffer using message as its initial contents.
func (*MessageBuffer) Bytes ¶
func (message *MessageBuffer) Bytes() []byte
Bytes gets the contents of the message buffer. This function is only useful after 'Write' operations as the underlying implementation will return the 'unread' portion of the buffer.
func (*MessageBuffer) ReadByte ¶
func (message *MessageBuffer) ReadByte() (byte, error)
ReadByte reads a byte from the message buffer.
This function will read and return the next available byte from the message buffer.
func (*MessageBuffer) ReadInt32 ¶
func (message *MessageBuffer) ReadInt32() (value int32, err error)
ReadInt32 reads an int32 from the message buffer.
This function will read the next 4 available bytes from the message buffer and return them as an int32.
panic on error.
func (*MessageBuffer) ReadString ¶
func (message *MessageBuffer) ReadString() (string, error)
ReadString reads a string from the message buffer.
This function will read and return the next Null terminated string from the message buffer.
func (*MessageBuffer) ResetLength ¶
func (message *MessageBuffer) ResetLength(offset int)
ResetLength will reset the message length for the message.
offset should be one of the PGMessageLengthOffset* constants.
func (*MessageBuffer) WriteByte ¶
func (message *MessageBuffer) WriteByte(value byte) error
WriteByte will write the specified byte to the message buffer.
func (*MessageBuffer) WriteInt32 ¶
func (message *MessageBuffer) WriteInt32(value int32) (err error)
WriteInt32 will write a 4 byte int32 to the message buffer.
func (*MessageBuffer) WriteString ¶
func (message *MessageBuffer) WriteString(value string) (int, error)
WriteString will write a NULL terminated string to the buffer. It is assumed that the incoming string has *NOT* been NULL terminated.