Documentation ¶
Overview ¶
Package network This code is adapted from the "github.com/labstack/echo" project, specifically the file "router.go," which is licensed under the MIT License.
Index ¶
- Constants
- Variables
- func AddToHook() hook.Register
- func AddToScheme() scheme.Register
- func NewHTTPNodeCodec() scheme.Codec
- func NewListenNodeCodec() scheme.Codec
- func NewRouteNodeCodec() scheme.Codec
- func NewUpgradeNodeCodec() scheme.Codec
- func NewWebSocketNodeCodec() scheme.Codec
- type HTTPListenNode
- func (n *HTTPListenNode) Address() net.Addr
- func (n *HTTPListenNode) Close() error
- func (n *HTTPListenNode) In(_ string) *port.InPort
- func (n *HTTPListenNode) Listen() error
- func (n *HTTPListenNode) Out(name string) *port.OutPort
- func (n *HTTPListenNode) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (n *HTTPListenNode) Shutdown() error
- func (n *HTTPListenNode) TLS(cert, key string) error
- type HTTPNode
- type HTTPNodeSpec
- type HTTPPayload
- type ListenNodeSpec
- type Route
- type RouteNode
- type RouteNodeSpec
- type TLS
- type UpgradeNodeSpec
- type WebSocketConnNode
- type WebSocketNode
- type WebSocketNodeSpec
- type WebSocketPayload
- type WebSocketUpgradeNode
- func (n *WebSocketUpgradeNode) ReadBufferSize() int
- func (n *WebSocketUpgradeNode) SetReadBufferSize(size int)
- func (n *WebSocketUpgradeNode) SetTimeout(timeout time.Duration)
- func (n *WebSocketUpgradeNode) SetWriteBufferSize(size int)
- func (n *WebSocketUpgradeNode) Timeout() time.Duration
- func (n *WebSocketUpgradeNode) WriteBufferSize() int
Constants ¶
const ( KeyHTTPRequest = "__http.Request__" KeyHTTPResponseWriter = "__http.ResponseWriter__" )
const KindHTTP = "http"
const KindListener = "listener"
const KindRouter = "router"
const KindUpgrader = "upgrader"
const KindWebSocket = "websocket"
const ProtocolHTTP = "http"
const ProtocolWebsocket = "websocket"
Variables ¶
var ErrInvalidProtocol = errors.New("protocol is invalid")
Functions ¶
func AddToScheme ¶
AddToScheme returns a function that adds node types and codecs to the provided spec.
func NewHTTPNodeCodec ¶
NewHTTPNodeCodec creates a new codec for HTTPNode.
func NewListenNodeCodec ¶
NewListenNodeCodec creates a new codec for ListenNodeSpec.
func NewRouteNodeCodec ¶
NewRouteNodeCodec creates a new codec for RouteNodeSpec.
func NewUpgradeNodeCodec ¶ added in v0.13.0
NewUpgradeNodeCodec creates a new codec for UpgradeNodeSpec.
func NewWebSocketNodeCodec ¶
NewWebSocketNodeCodec creates a new codec for WebSocketNodeSpec.
Types ¶
type HTTPListenNode ¶
type HTTPListenNode struct {
// contains filtered or unexported fields
}
HTTPListenNode represents a Node for handling HTTP requests.
func NewHTTPListenNode ¶
func NewHTTPListenNode(address string) *HTTPListenNode
NewHTTPListenNode creates a new HTTPListenNode with the specified address.
func (*HTTPListenNode) Address ¶
func (n *HTTPListenNode) Address() net.Addr
Address returns the listener address if available.
func (*HTTPListenNode) Close ¶
func (n *HTTPListenNode) Close() error
Close closes all ports and stops the HTTP server.
func (*HTTPListenNode) In ¶
func (n *HTTPListenNode) In(_ string) *port.InPort
In returns the input port with the specified name.
func (*HTTPListenNode) Listen ¶
func (n *HTTPListenNode) Listen() error
Listen starts the HTTP server.
func (*HTTPListenNode) Out ¶
func (n *HTTPListenNode) Out(name string) *port.OutPort
Out returns the output port with the specified name.
func (*HTTPListenNode) ServeHTTP ¶
func (n *HTTPListenNode) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles HTTP requests.
func (*HTTPListenNode) Shutdown ¶
func (n *HTTPListenNode) Shutdown() error
Shutdown shuts down the HTTPListenNode by closing the server and its associated listener.
func (*HTTPListenNode) TLS ¶ added in v0.10.0
func (n *HTTPListenNode) TLS(cert, key string) error
TLS configures the HTTP server to use TLS with the provided certificate and key.
type HTTPNode ¶
type HTTPNode struct { *node.OneToOneNode // contains filtered or unexported fields }
HTTPNode represents a node for making HTTP client requests.
func NewHTTPNode ¶
NewHTTPNode creates a new HTTPNode instance.
func (*HTTPNode) SetTimeout ¶
SetTimeout sets the timeout duration for the HTTP request.
type HTTPNodeSpec ¶
type HTTPNodeSpec struct { spec.Meta `map:",inline"` URL string `map:"url" validate:"required,url"` Timeout time.Duration `map:"timeout,omitempty"` }
HTTPNodeSpec defines the specifications for creating an HTTPNode.
type HTTPPayload ¶
type HTTPPayload struct { Method string `map:"method,omitempty"` Scheme string `map:"scheme,omitempty"` Host string `map:"host,omitempty"` Path string `map:"path,omitempty"` Query url.Values `map:"query,omitempty"` Protocol string `map:"protocol,omitempty"` Header http.Header `map:"header,omitempty"` Body types.Value `map:"body,omitempty"` Status int `map:"status"` }
HTTPPayload is the payload structure for HTTP requests and responses.
func NewHTTPPayload ¶
func NewHTTPPayload(status int, bodies ...types.Value) *HTTPPayload
NewHTTPPayload creates a new HTTPPayload with the given HTTP status code and optional body.
type ListenNodeSpec ¶
type ListenNodeSpec struct { spec.Meta `map:",inline"` Protocol string `map:"protocol" validate:"required"` Host string `map:"host,omitempty" validate:"omitempty,hostname|ip"` Port int `map:"port" validate:"required"` TLS TLS `map:"tls"` }
ListenNodeSpec defines the specifications for creating a ListenNode.
type Route ¶
type Route struct { Method string `map:"method" validate:"required"` Path string `map:"path" validate:"required"` Port string `map:"port" validate:"required"` }
Route represents a routing configuration with a specific HTTP method, path, and port.
type RouteNode ¶
type RouteNode struct { *node.OneToManyNode // contains filtered or unexported fields }
RouteNode represents a node for routing based on HTTP method, path, and port.
type RouteNodeSpec ¶
type RouteNodeSpec struct { spec.Meta `map:",inline"` Routes []Route `map:"routes" validate:"required"` }
RouteNodeSpec defines the specification for configuring a RouteNode.
type UpgradeNodeSpec ¶ added in v0.13.0
type UpgradeNodeSpec struct { spec.Meta `map:",inline"` Protocol string `map:"protocol" validate:"required"` Timeout time.Duration `map:"timeout,omitempty"` Buffer int `map:"buffer,omitempty"` }
UpgradeNodeSpec defines the specifications for creating a UpgradeNode.
type WebSocketConnNode ¶
type WebSocketConnNode struct {
// contains filtered or unexported fields
}
WebSocketConnNode represents a node for handling WebSocket connection.
func NewWebSocketConnNode ¶
func NewWebSocketConnNode(action func(*process.Process, *packet.Packet) (*websocket.Conn, error)) *WebSocketConnNode
NewWebSocketConnNode creates a new WebSocketConnNode.
func (*WebSocketConnNode) Close ¶
func (n *WebSocketConnNode) Close() error
Close closes all ports of the WebSocketConnNode.
type WebSocketNode ¶
type WebSocketNode struct { *WebSocketConnNode // contains filtered or unexported fields }
WebSocketNode represents a node for establishing WebSocket client connection.
func NewWebSocketNode ¶
func NewWebSocketNode(url *url.URL) *WebSocketNode
NewWebSocketNode creates a new WebSocketNode.
func (*WebSocketNode) SetTimeout ¶
func (n *WebSocketNode) SetTimeout(timeout time.Duration)
SetTimeout sets the handshake timeout for WebSocket conns.
type WebSocketNodeSpec ¶
type WebSocketNodeSpec struct { spec.Meta `map:",inline"` URL string `map:"url" validate:"required,url"` Timeout time.Duration `map:"timeout,omitempty"` }
WebSocketNodeSpec defines the specifications for creating a WebSocketNode.
type WebSocketPayload ¶
WebSocketPayload represents the payload structure for WebSocket messages.
type WebSocketUpgradeNode ¶
type WebSocketUpgradeNode struct { *WebSocketConnNode // contains filtered or unexported fields }
WebSocketUpgradeNode is a node for upgrading an HTTP connection to a WebSocket connection.
func NewWebSocketUpgradeNode ¶
func NewWebSocketUpgradeNode() *WebSocketUpgradeNode
NewWebSocketUpgradeNode creates a new WebSocketUpgradeNode.
func (*WebSocketUpgradeNode) ReadBufferSize ¶
func (n *WebSocketUpgradeNode) ReadBufferSize() int
ReadBufferSize returns the read buffer size.
func (*WebSocketUpgradeNode) SetReadBufferSize ¶
func (n *WebSocketUpgradeNode) SetReadBufferSize(size int)
SetReadBufferSize sets the read buffer size.
func (*WebSocketUpgradeNode) SetTimeout ¶
func (n *WebSocketUpgradeNode) SetTimeout(timeout time.Duration)
SetTimeout sets the timeout duration.
func (*WebSocketUpgradeNode) SetWriteBufferSize ¶
func (n *WebSocketUpgradeNode) SetWriteBufferSize(size int)
SetWriteBufferSize sets the write buffer size.
func (*WebSocketUpgradeNode) Timeout ¶
func (n *WebSocketUpgradeNode) Timeout() time.Duration
Timeout returns the timeout duration.
func (*WebSocketUpgradeNode) WriteBufferSize ¶
func (n *WebSocketUpgradeNode) WriteBufferSize() int
WriteBufferSize returns the write buffer size.