Skip to content

Commit

Permalink
feat: change types marshal tag to 'json' for improve capacity json
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Feb 8, 2025
1 parent af3ed4c commit 2663616
Show file tree
Hide file tree
Showing 39 changed files with 232 additions and 134 deletions.
4 changes: 2 additions & 2 deletions docs/user_extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ You can simplify this with `spec.Meta`:

```go
type ProxyNodeSpec struct {
spec.Meta `map:",inline"`
URLs []string `map:"urls"`
spec.Meta `json:",inline"`
URLs []string `json:"urls"`
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/user_extensions_kr.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ Env map[string][]Value // 노드에 필요한 환경 변수를 지정합니다.

```go
type ProxyNodeSpec struct {
spec.Meta `map:",inline"`
URLs []string `map:"urls"`
spec.Meta `json:",inline"`
URLs []string `json:"urls"`
}
```

Expand Down
8 changes: 4 additions & 4 deletions ext/pkg/control/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

// BlockNodeSpec defines the specification for creating a BlockNode.
type BlockNodeSpec struct {
spec.Meta `map:",inline"`
Specs []*spec.Unstructured `map:"specs"`
Inbounds map[string][]spec.Port `map:"inbounds,omitempty"`
Outbounds map[string][]spec.Port `map:"outbounds,omitempty"`
spec.Meta `json:",inline"`
Specs []*spec.Unstructured `json:"specs"`
Inbounds map[string][]spec.Port `json:"inbounds,omitempty"`
Outbounds map[string][]spec.Port `json:"outbounds,omitempty"`
}

const KindBlock = "block"
Expand Down
6 changes: 3 additions & 3 deletions ext/pkg/control/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

// CacheNodeSpec represents the specification for a cache node.
type CacheNodeSpec struct {
spec.Meta `map:",inline"`
Capacity int `map:"capacity,omitempty"`
Interval time.Duration `map:"interval,omitempty"`
spec.Meta `json:",inline"`
Capacity int `json:"capacity,omitempty"`
Interval time.Duration `json:"interval,omitempty"`
}

// CacheNode represents a node in the cache.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/for.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// ForNodeSpec defines the specifications for creating a ForNode.
type ForNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// ForNode processes input data in batches, splitting packets into sub-packets and handling them accordingly.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// ForkNodeSpec defines the specification for creating a ForkNode.
type ForkNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// ForkNode asynchronously branches the data processing flow into separate processes.
Expand Down
6 changes: 3 additions & 3 deletions ext/pkg/control/if.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (

// IfNodeSpec defines the specifications for creating an IfNode.
type IfNodeSpec struct {
spec.Meta `map:",inline"`
When string `map:"when" validate:"required"`
Timeout time.Duration `map:"timeout,omitempty"`
spec.Meta `json:",inline"`
When string `json:"when" validate:"required"`
Timeout time.Duration `json:"timeout,omitempty"`
}

// IfNode evaluates a condition and routes packets based on the result.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// MergeNodeSpec defines the specifications for creating a MergeNode.
type MergeNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// MergeNode represents a node that merges multiple input packets into a single output packet.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/nop.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// NOPNodeSpec defines the specification for creating a NOPNode.
type NOPNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// NOPNode represents a node that performs no operation and simply forwards incoming packets.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// PipeNodeSpec holds the specification for creating a PipeNode.
type PipeNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// PipeNode processes an input packet and sends the result to multiple output ports.
Expand Down
4 changes: 2 additions & 2 deletions ext/pkg/control/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

// RetryNodeSpec defines the configuration for RetryNode.
type RetryNodeSpec struct {
spec.Meta `map:",inline"`
Threshold int `map:"threshold,omitempty"`
spec.Meta `json:",inline"`
Threshold int `json:"threshold,omitempty"`
}

// RetryNode attempts to process packets up to a specified retry limit.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// SessionNodeSpec defines the specification for creating a SessionNode.
type SessionNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// SessionNode manages session data flow and process interactions through its ports.
Expand Down
4 changes: 2 additions & 2 deletions ext/pkg/control/sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

// SleepNodeSpec defines the configuration for SleepNode.
type SleepNodeSpec struct {
spec.Meta `map:",inline"`
Interval time.Duration `map:"interval" validate:"required"`
spec.Meta `json:",inline"`
Interval time.Duration `json:"interval" validate:"required"`
}

// SleepNode adds a delay to packet processing, using a specified interval.
Expand Down
8 changes: 4 additions & 4 deletions ext/pkg/control/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (

// SnippetNodeSpec defines the specifications for creating a SnippetNode.
type SnippetNodeSpec struct {
spec.Meta `map:",inline"`
Language string `map:"language" validate:"required"`
Code string `map:"code" validate:"required"`
Timeout time.Duration `map:"timeout,omitempty"`
spec.Meta `json:",inline"`
Language string `json:"language" validate:"required"`
Code string `json:"code" validate:"required"`
Timeout time.Duration `json:"timeout,omitempty"`
}

// SnippetNode represents a node that executes code snippets in various languages.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// SplitNodeSpec defines the specifications for creating a SplitNode.
type SplitNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// SplitNode represents a node that splits incoming packets into multiple packets.
Expand Down
4 changes: 2 additions & 2 deletions ext/pkg/control/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

// StepNodeSpec defines the specification for creating a StepNode.
type StepNodeSpec struct {
spec.Meta `map:",inline"`
Specs []*spec.Unstructured `map:"specs"`
spec.Meta `json:",inline"`
Specs []*spec.Unstructured `json:"specs"`
}

const KindStep = "step"
Expand Down
10 changes: 5 additions & 5 deletions ext/pkg/control/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (

// SwitchNodeSpec holds specifications for creating a SwitchNode.
type SwitchNodeSpec struct {
spec.Meta `map:",inline"`
Matches []Condition `map:"matches" validate:"required"`
Timeout time.Duration `map:"timeout,omitempty"`
spec.Meta `json:",inline"`
Matches []Condition `json:"matches" validate:"required"`
Timeout time.Duration `json:"timeout,omitempty"`
}

// Condition represents a condition for directing packets to specific ports.
type Condition struct {
When string `map:"when" validate:"required"`
Port string `map:"port" validate:"required"`
When string `json:"when" validate:"required"`
Port string `json:"port" validate:"required"`
}

// SwitchNode directs packets to different ports based on specified conditions.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/throw.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// ThrowNodeSpec defines the specification for the ThrowNode.
type ThrowNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// ThrowNode represents a node that throws errors based on incoming packets.
Expand Down
2 changes: 1 addition & 1 deletion ext/pkg/control/try.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// TryNodeSpec defines the specification for creating a TryNode.
type TryNodeSpec struct {
spec.Meta `map:",inline"`
spec.Meta `json:",inline"`
}

// TryNode represents a node that processes packets and handles errors.
Expand Down
4 changes: 2 additions & 2 deletions ext/pkg/io/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

// PrintNodeSpec specifies the PrintNode configuration, including metadata and filename.
type PrintNodeSpec struct {
spec.Meta `map:",inline"`
Filename string `map:"filename,omitempty"`
spec.Meta `json:",inline"`
Filename string `json:"filename,omitempty"`
}

// PrintNode writes data to a file according to a format string.
Expand Down
4 changes: 2 additions & 2 deletions ext/pkg/io/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

// ScanNodeSpec specifies the ScanNode configuration, including metadata and filename.
type ScanNodeSpec struct {
spec.Meta `map:",inline"`
Filename string `map:"filename,omitempty"`
spec.Meta `json:",inline"`
Filename string `json:"filename,omitempty"`
}

// ScanNode reads from a file and parses data according to a format string.
Expand Down
8 changes: 4 additions & 4 deletions ext/pkg/io/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (

// SQLNodeSpec defines the specifications for creating a SQLNode.
type SQLNodeSpec struct {
spec.Meta `map:",inline"`
Driver string `map:"driver" validate:"required"`
Source string `map:"source" validate:"required"`
Isolation sql.IsolationLevel `map:"isolation,omitempty"`
spec.Meta `json:",inline"`
Driver string `json:"driver" validate:"required"`
Source string `json:"source" validate:"required"`
Isolation sql.IsolationLevel `json:"isolation,omitempty"`
}

// SQLNode represents a node for interacting with a relational database.
Expand Down
24 changes: 12 additions & 12 deletions ext/pkg/network/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (

// HTTPNodeSpec defines the specifications for creating an HTTPNode.
type HTTPNodeSpec struct {
spec.Meta `map:",inline"`
URL string `map:"url" validate:"required,url"`
Timeout time.Duration `map:"timeout,omitempty"`
spec.Meta `json:",inline"`
URL string `json:"url" validate:"required,url"`
Timeout time.Duration `json:"timeout,omitempty"`
}

// HTTPNode represents a node for making HTTP client requests.
Expand All @@ -37,15 +37,15 @@ type HTTPNode struct {

// HTTPPayload is the payload structure for HTTP requests and responses.
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"`
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"`
}

const KindHTTP = "http"
Expand Down
14 changes: 7 additions & 7 deletions ext/pkg/network/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import (

// ListenNodeSpec defines the specifications for creating a ListenNode.
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"`
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"`
}

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

// HTTPListenNode represents a Node for handling HTTP requests.
Expand Down
10 changes: 5 additions & 5 deletions ext/pkg/network/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (

// RouteNodeSpec defines the specification for configuring a RouteNode.
type RouteNodeSpec struct {
spec.Meta `map:",inline"`
Routes []Route `map:"routes" validate:"required"`
spec.Meta `json:",inline"`
Routes []Route `json:"routes" validate:"required"`
}

// Route represents a routing configuration with a specific HTTP method, path, and port.
type Route struct {
Method string `map:"method" validate:"required"`
Path string `map:"path" validate:"required"`
Port string `map:"port" validate:"required"`
Method string `json:"method" validate:"required"`
Path string `json:"path" validate:"required"`
Port string `json:"port" validate:"required"`
}

// RouteNode represents a node for routing based on HTTP method, path, and port.
Expand Down
8 changes: 4 additions & 4 deletions ext/pkg/network/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (

// UpgradeNodeSpec defines the specifications for creating a UpgradeNode.
type UpgradeNodeSpec struct {
spec.Meta `map:",inline"`
Protocol string `map:"protocol" validate:"required"`
Timeout time.Duration `map:"timeout,omitempty"`
Buffer int `map:"buffer,omitempty"`
spec.Meta `json:",inline"`
Protocol string `json:"protocol" validate:"required"`
Timeout time.Duration `json:"timeout,omitempty"`
Buffer int `json:"buffer,omitempty"`
}

// WebSocketUpgradeNode is a node for upgrading an HTTP connection to a WebSocket connection.
Expand Down
10 changes: 5 additions & 5 deletions ext/pkg/network/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (

// WebSocketNodeSpec defines the specifications for creating a WebSocketNode.
type WebSocketNodeSpec struct {
spec.Meta `map:",inline"`
URL string `map:"url" validate:"required,url"`
Timeout time.Duration `map:"timeout,omitempty"`
spec.Meta `json:",inline"`
URL string `json:"url" validate:"required,url"`
Timeout time.Duration `json:"timeout,omitempty"`
}

// WebSocketNode represents a node for establishing WebSocket client connection.
Expand All @@ -46,8 +46,8 @@ type WebSocketConnNode struct {

// WebSocketPayload represents the payload structure for WebSocket messages.
type WebSocketPayload struct {
Type int `map:"type"`
Data types.Value `map:"data,omitempty"`
Type int `json:"type"`
Data types.Value `json:"data,omitempty"`
}

const KindWebSocket = "websocket"
Expand Down
4 changes: 2 additions & 2 deletions ext/pkg/system/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

// SignalNodeSpec defines the specifications for creating a SignalNode.
type SignalNodeSpec struct {
spec.Meta `map:",inline"`
Topic string `map:"topic" validate:"required"`
spec.Meta `json:",inline"`
Topic string `json:"topic" validate:"required"`
}

// SignalNode listens to a signal channel and forwards signals as packets.
Expand Down
4 changes: 2 additions & 2 deletions ext/pkg/system/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

// SyscallNodeSpec specifies the creation parameters for a SyscallNode.
type SyscallNodeSpec struct {
spec.Meta `map:",inline"`
OPCode string `map:"opcode" validate:"required"`
spec.Meta `json:",inline"`
OPCode string `json:"opcode" validate:"required"`
}

// SyscallNode executes synchronized function.
Expand Down
Loading

0 comments on commit 2663616

Please sign in to comment.