node

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: MIT Imports: 22 Imported by: 0

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

View Source
const (
	KeyHTTPRequest        = "__http.Request__"
	KeyHTTPResponseWriter = "__http.ResponseWriter__"
)
View Source
const KindHTTP = "http"
View Source
const KindListener = "listener"
View Source
const KindRouter = "router"
View Source
const ProtocolHTTP = "http"

Variables

View Source
var ErrInvalidProtocol = errors.New("protocol is invalid")

Functions

func NewHTTPNodeCodec

func NewHTTPNodeCodec() scheme.Codec

NewHTTPNodeCodec creates a new codec for HTTPNode.

func NewListenNodeCodec

func NewListenNodeCodec() scheme.Codec

NewListenNodeCodec creates a new codec for ListenNodeSpec.

func NewRouteNodeCodec

func NewRouteNodeCodec() scheme.Codec

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

func NewHTTPNode(client *http.Client) *HTTPNode

NewHTTPNode creates a new HTTPNode instance.

func (*HTTPNode) SetTimeout

func (n *HTTPNode) SetTimeout(timeout time.Duration)

SetTimeout sets the timeout duration for the HTTP request.

func (*HTTPNode) SetURL

func (n *HTTPNode) SetURL(url *url.URL)

SetURL sets the URL 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.

func NewRouteNode

func NewRouteNode() *RouteNode

NewRouteNode creates a new RouteNode.

func (*RouteNode) Add

func (n *RouteNode) Add(method, path, port string)

Add adds a new route to the routing tree for the specified HTTP method, path, and port.

func (*RouteNode) Find

func (n *RouteNode) Find(method, path string) (string, map[string]string)

Find searches for a matching route based on the provided HTTP method and path.

type RouteNodeSpec

type RouteNodeSpec struct {
	spec.Meta `json:",inline"`
	Routes    []Route `json:"routes" validate:"required"`
}

RouteNodeSpec defines the specification for configuring a RouteNode.

type TLS

type TLS struct {
	Cert []byte `json:"cert,omitempty"`
	Key  []byte `json:"key,omitempty"`
}

Jump to

Keyboard shortcuts

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