Documentation
¶
Overview ¶
Package node 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 NewHTTPNodeCodec() scheme.Codec
- func NewListenNodeCodec() scheme.Codec
- func NewRouteNodeCodec() 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 []byte) error
- type HTTPNode
- type HTTPNodeSpec
- type HTTPPayload
- type ListenNodeSpec
- type Route
- type RouteNode
- type RouteNodeSpec
- type TLS
Constants ¶
const ( KeyHTTPRequest = "__http.Request__" KeyHTTPResponseWriter = "__http.ResponseWriter__" )
const KindHTTP = "http"
const KindListener = "listener"
const KindRouter = "router"
const ProtocolHTTP = "http"
Variables ¶
var ErrInvalidProtocol = errors.New("protocol is invalid")
Functions ¶
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.
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 ¶
func (n *HTTPListenNode) TLS(cert, key []byte) 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 `json:",inline"`
URL string `json:"url" validate:"required,url"`
Timeout time.Duration `json:"timeout,omitempty"`
}
HTTPNodeSpec defines the specifications for creating an HTTPNode.
type HTTPPayload ¶
type HTTPPayload struct {
Method string `json:"method,omitempty"`
Scheme string `json:"scheme,omitempty"`
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Query url.Values `json:"query,omitempty"`
Protocol string `json:"protocol,omitempty"`
Header http.Header `json:"header,omitempty"`
Body types.Value `json:"body,omitempty"`
Status int `json:"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 `json:",inline"`
Protocol string `json:"protocol" validate:"required"`
Host string `json:"host,omitempty" validate:"omitempty,hostname|ip"`
Port int `json:"port" validate:"required"`
TLS TLS `json:"tls"`
}
ListenNodeSpec defines the specifications for creating a ListenNode.
type Route ¶
type Route struct {
Method string `json:"method" validate:"required"`
Path string `json:"path" validate:"required"`
Port string `json:"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 `json:",inline"`
Routes []Route `json:"routes" validate:"required"`
}
RouteNodeSpec defines the specification for configuring a RouteNode.