Documentation ¶
Overview ¶
Package asgi implements the asgi specs defined at
https://channels.readthedocs.io/en/latest/asgi.html
On the networklayer it should be fully compatible with the spec. But the methods and functions defined differ from the spec to be more go-like.
Index ¶
- func ConvertHeader(httpHeaders http.Header) (headers [][2][]byte)
- func GetChannelnameRandom() string
- func IsChannelFullError(err error) bool
- type ChannelFullError
- type ChannelLayer
- type ConnectionMessage
- type DisconnectionMessage
- type ForwardError
- type Message
- type Messager
- type ReceiveMessage
- type ReceiveMessenger
- type RequestBodyChunkMessage
- type RequestMessage
- type ResponseChunkMessage
- type ResponseMessage
- type SendCloseAcceptMessage
- type SendMessenger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertHeader ¶
ConvertHeader converts http.Headers in the form that the asgi specs expects them
func GetChannelnameRandom ¶
func GetChannelnameRandom() string
GetChannelnameRandom creates a random string that can be added as suffix to a channel name
func IsChannelFullError ¶
IsChannelFullError returns true, if the error is an ChannelFullError If the error is a ForwardError, then return true, if one of the inner errors is a ChannelFullError
Types ¶
type ChannelFullError ¶
type ChannelFullError struct {
Channel string
}
ChannelFullError is used, when a channel is full
func (ChannelFullError) Error ¶
func (e ChannelFullError) Error() string
type ChannelLayer ¶
type ChannelLayer interface { // Send sends a message to a channel. The first argument has to be a channel // name. The second argument has to be a raw message dict. Send(channel string, message Message) (err error) // Receive listens to a list of channels and gets a message from it. The first // argument is a slice (list) of channel names. The second argument determinis // if the method should block until there is a message to receive or if the // method should return at once. // The method returns the channel name from which a value was received or an // empty string, if no value could be received. The second return value is the // received raw message. Receive(channels []string, block bool) (channelname string, message Message, err error) // NewChannel taks a prefix of a channlname and adds a unique suffix. It also // returns an error, if some happen. NewChannel(string) (string, error) }
ChannelLayer is a interface with the base methods to send and receive messages
type ConnectionMessage ¶
type ConnectionMessage struct { ReplyChannel string Scheme string Path string QueryString []byte RootPath string Headers http.Header Client string Server string }
ConnectionMessage is a structured message defined by the asgi specs. It is used to forware an websocket connection request to the channel layer. It differs from the asgi specs that all fields are Uppercase and CamelCase, the field Headers is a dict and the fields Client and Server are strings in the form "host:port". It has no field order.
func (*ConnectionMessage) Raw ¶
func (cm *ConnectionMessage) Raw() Message
Raw converts a ConnectionMessage to a Message dict, that can be send through the channel layer
type DisconnectionMessage ¶
DisconnectionMessage is a structured message defined by the asgi specs. It is send to the channel layer when the connection was closed for any reason. It differs from the asgi specs that all fields are Uppercase and CamelCase.
func (*DisconnectionMessage) Raw ¶
func (dm *DisconnectionMessage) Raw() Message
Raw converts a DisconnectionMessage to a Message, that can be send through the channel layer.
type ForwardError ¶
type ForwardError struct {
// contains filtered or unexported fields
}
ForwardError is an error that holds another error inside
func NewForwardError ¶
func NewForwardError(s string, e error) *ForwardError
NewForwardError creates a new ForwardError.
func (*ForwardError) Error ¶
func (e *ForwardError) Error() string
type Message ¶
type Message map[string]interface{}
Message is a dict to send via the channel layer. The key has to be a string and the type of the value vary.
type Messager ¶
type Messager interface { SendMessenger ReceiveMessenger }
Messager is an type that can be used to send and receive messages.
type ReceiveMessage ¶
type ReceiveMessage struct { ReplyChannel string Path string Content []byte Type int // See websocket.TextMessage and websocket.BinaryMessage Order int }
ReceiveMessage is message specified by the asgi spec
func (*ReceiveMessage) Raw ¶
func (cm *ReceiveMessage) Raw() Message
Raw Converts a ReceiveMessage to a Message
type ReceiveMessenger ¶
type ReceiveMessenger interface { // Sets the values of the variable with the values of a Message dict. Set(Message) error }
ReceiveMessenger is a type that can be used to receive a message through the channel layer. Therefore it has the method to convert a Message dict to a structured message type.
type RequestBodyChunkMessage ¶
RequestBodyChunkMessage is a structured message type, defined by the asgi specs which is used to continue forwarding an http request from a client to the channel layer, if the request body was big. This differs from the specs that all fields are uppercase and CamelCase.
func (*RequestBodyChunkMessage) Raw ¶
func (r *RequestBodyChunkMessage) Raw() Message
Raw converts a RequestBodyChunkMessage to a Message dict.
type RequestMessage ¶
type RequestMessage struct { ReplyChannel string HTTPVersion string Method string Scheme string Path string QueryString []byte RootPath string Headers http.Header Body []byte BodyChannel string Client string Server string }
RequestMessage is a structured message type, defined by the asgi specs which is used to forward an http request from a client to the channel layer. This differs from the specs that all fields are uppercase and CamelCase. Also the Headers field has the type http.Header and therefore is a dictonary. BodyChannel does not default to None but to an empty string. Client and Server are strings in the form "host:port". They default to an empty string.
func (*RequestMessage) Raw ¶
func (r *RequestMessage) Raw() Message
Raw converts a RequestMessage to a Message dict.
type ResponseChunkMessage ¶
ResponseChunkMessage is a structured message type, defined by the asgi specs. It is used to forward an response from the channel layer to the client. It has to follow a ResponseMessage. It differs from the specs that the fields are uppercase and CamelCase.
func (*ResponseChunkMessage) Set ¶
func (rm *ResponseChunkMessage) Set(m Message) (err error)
Set fills the values of a ResponseChunkMessage with a the data of a message dict.
type ResponseMessage ¶
type ResponseMessage struct { ResponseChunkMessage Status int Headers http.Header }
ResponseMessage is a structured message type, defined by the asgi specs. It is used to forward an response from the channel layer to the client. It differs from the specs that the fields are uppercase and CamelCase and that Headers is a dictonary and not a list of tuples.
func (*ResponseMessage) Set ¶
func (rm *ResponseMessage) Set(m Message) (err error)
Set fills the values of a ResponseMessage with a the data of a message dict.
type SendCloseAcceptMessage ¶
SendCloseAcceptMessage is a structured message defined by the asgi specs. It is used as answer from the channel layer after a websocket connection and to s end data to an open websocket connection. It differs from the asgi specs that all fields are Uppercase and CamelCase.
func (*SendCloseAcceptMessage) Set ¶
func (s *SendCloseAcceptMessage) Set(m Message) (err error)
Set fills the values of a SendCloseAcceptMessage with a the data of a message dict.
type SendMessenger ¶
type SendMessenger interface { // Converts a Message to a Message dict, that can be send through a asgi channel. Raw() Message }
SendMessenger is an type that can be used to send a message through the channel layer. Therefore it has the method to convert a structured message to a Message dict.