This commit is contained in:
sujit
2025-09-18 10:15:26 +05:45
parent 651c7335bc
commit 3606fca4ae
6 changed files with 1439 additions and 155 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,28 @@
package main package main
import ( import (
"encoding/json"
"flag" "flag"
"fmt"
"io/ioutil"
"log" "log"
"os" "os"
) )
func loadConfiguration(configPath string) (*AppConfiguration, error) {
data, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %v", err)
}
var config AppConfiguration
if err := json.Unmarshal(data, &config); err != nil {
return nil, fmt.Errorf("failed to parse JSON config: %v", err)
}
return &config, nil
}
func main() { func main() {
// Parse command line flags // Parse command line flags
configPath := flag.String("config", "sms-app.json", "Path to JSON configuration file") configPath := flag.String("config", "sms-app.json", "Path to JSON configuration file")
@@ -16,14 +33,15 @@ func main() {
*configPath = os.Args[1] *configPath = os.Args[1]
} }
// Create JSON engine // Load configuration first
engine := NewJSONEngine() config, err := loadConfiguration(*configPath)
if err != nil {
// Load configuration
if err := engine.LoadConfiguration(*configPath); err != nil {
log.Fatalf("Failed to load configuration: %v", err) log.Fatalf("Failed to load configuration: %v", err)
} }
// Create JSON engine with configuration
engine := NewJSONEngine(config)
// Compile configuration // Compile configuration
if err := engine.Compile(); err != nil { if err := engine.Compile(); err != nil {
log.Fatalf("Failed to compile configuration: %v", err) log.Fatalf("Failed to compile configuration: %v", err)

View File

@@ -7,14 +7,15 @@ import (
// AppConfiguration represents the complete JSON configuration for an application // AppConfiguration represents the complete JSON configuration for an application
type AppConfiguration struct { type AppConfiguration struct {
App AppMetadata `json:"app"` App AppMetadata `json:"app"`
Routes []RouteConfig `json:"routes"` WorkflowEngine *WorkflowEngineConfig `json:"workflow_engine,omitempty"`
Middleware []MiddlewareConfig `json:"middleware"` Routes []RouteConfig `json:"routes"`
Templates map[string]TemplateConfig `json:"templates"` Middleware []MiddlewareConfig `json:"middleware"`
Workflows []WorkflowConfig `json:"workflows"` Templates map[string]TemplateConfig `json:"templates"`
Data map[string]interface{} `json:"data"` Workflows []WorkflowConfig `json:"workflows"`
Functions map[string]FunctionConfig `json:"functions"` Data map[string]interface{} `json:"data"`
Validators map[string]ValidatorConfig `json:"validators"` Functions map[string]FunctionConfig `json:"functions"`
Validators map[string]ValidatorConfig `json:"validators"`
} }
// AppMetadata contains basic app information // AppMetadata contains basic app information
@@ -26,6 +27,30 @@ type AppMetadata struct {
Host string `json:"host"` Host string `json:"host"`
} }
// WorkflowEngineConfig contains workflow engine configuration
type WorkflowEngineConfig struct {
MaxWorkers int `json:"max_workers,omitempty"`
ExecutionTimeout string `json:"execution_timeout,omitempty"`
EnableMetrics bool `json:"enable_metrics,omitempty"`
EnableAudit bool `json:"enable_audit,omitempty"`
EnableTracing bool `json:"enable_tracing,omitempty"`
LogLevel string `json:"log_level,omitempty"`
Storage StorageConfig `json:"storage,omitempty"`
Security SecurityConfig `json:"security,omitempty"`
}
// StorageConfig contains storage configuration
type StorageConfig struct {
Type string `json:"type,omitempty"`
MaxConnections int `json:"max_connections,omitempty"`
}
// SecurityConfig contains security configuration
type SecurityConfig struct {
EnableAuth bool `json:"enable_auth,omitempty"`
AllowedOrigins []string `json:"allowed_origins,omitempty"`
}
// RouteConfig defines HTTP routes // RouteConfig defines HTTP routes
type RouteConfig struct { type RouteConfig struct {
Path string `json:"path"` Path string `json:"path"`
@@ -48,6 +73,7 @@ type ResponseConfig struct {
type HandlerConfig struct { type HandlerConfig struct {
Type string `json:"type"` // "workflow", "template", "function", "redirect" Type string `json:"type"` // "workflow", "template", "function", "redirect"
Target string `json:"target"` Target string `json:"target"`
Template string `json:"template,omitempty"`
Input map[string]interface{} `json:"input,omitempty"` Input map[string]interface{} `json:"input,omitempty"`
Output map[string]interface{} `json:"output,omitempty"` Output map[string]interface{} `json:"output,omitempty"`
ErrorHandling *ErrorHandlingConfig `json:"error_handling,omitempty"` ErrorHandling *ErrorHandlingConfig `json:"error_handling,omitempty"`
@@ -177,101 +203,72 @@ type JSONSchemaConfig struct {
Output map[string]interface{} `json:"output,omitempty"` Output map[string]interface{} `json:"output,omitempty"`
} }
// FunctionConfig defines custom functions // FunctionConfig defines custom functions with complete flexibility
type FunctionConfig struct { type FunctionConfig struct {
ID string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
Type string `json:"type"` // "builtin", "custom", "external", "http" Type string `json:"type"` // "http", "expression", "template", "js", "builtin"
Handler string `json:"handler,omitempty"` Handler string `json:"handler,omitempty"`
Method string `json:"method,omitempty"` // For HTTP functions Method string `json:"method,omitempty"` // For HTTP functions
URL string `json:"url,omitempty"` // For HTTP functions URL string `json:"url,omitempty"` // For HTTP functions
Headers map[string]string `json:"headers,omitempty"` // For HTTP functions Headers map[string]interface{} `json:"headers,omitempty"` // For HTTP functions
Code string `json:"code,omitempty"` // For custom code functions Body string `json:"body,omitempty"` // For HTTP request body template
Parameters []ParameterConfig `json:"parameters,omitempty"` Code string `json:"code,omitempty"` // For custom code functions
Returns []ParameterConfig `json:"returns,omitempty"` Template string `json:"template,omitempty"` // For template functions
Expression string `json:"expression,omitempty"` // For expression functions
Parameters map[string]interface{} `json:"parameters,omitempty"` // Generic parameters
Returns map[string]interface{} `json:"returns,omitempty"` // Generic return definition
Response map[string]interface{} `json:"response,omitempty"` // Response structure
Config map[string]interface{} `json:"config,omitempty"` Config map[string]interface{} `json:"config,omitempty"`
Async bool `json:"async"` Async bool `json:"async"`
Timeout string `json:"timeout,omitempty"` Timeout string `json:"timeout,omitempty"`
} }
// ParameterConfig defines function parameters // Note: ParameterConfig removed - using generic map[string]interface{} for parameters
type ParameterConfig struct {
Name string `json:"name"`
Type string `json:"type"`
Required bool `json:"required"`
Default interface{} `json:"default,omitempty"`
Description string `json:"description,omitempty"`
Validation []string `json:"validation,omitempty"`
}
// ValidatorConfig defines validation rules // ValidatorConfig defines validation rules with complete flexibility
type ValidatorConfig struct { type ValidatorConfig struct {
ID string `json:"id"` ID string `json:"id"`
Type string `json:"type"` // "jsonschema", "custom", "regex" Type string `json:"type"` // "jsonschema", "custom", "regex", "builtin"
Field string `json:"field,omitempty"` Field string `json:"field,omitempty"`
Schema interface{} `json:"schema,omitempty"` Schema interface{} `json:"schema,omitempty"`
Rules []ValidationRule `json:"rules,omitempty"` Rules map[string]interface{} `json:"rules,omitempty"` // Generic rules
Messages map[string]string `json:"messages,omitempty"` Messages map[string]string `json:"messages,omitempty"`
StrictMode bool `json:"strict_mode"` Expression string `json:"expression,omitempty"` // For expression-based validation
AllowEmpty bool `json:"allow_empty"` Config map[string]interface{} `json:"config,omitempty"`
StrictMode bool `json:"strict_mode"`
AllowEmpty bool `json:"allow_empty"`
} }
// ValidationRule defines individual validation rules // ValidationRule defines individual validation rules with flexibility
type ValidationRule struct { type ValidationRule struct {
Field string `json:"field"` Field string `json:"field"`
Type string `json:"type"` Type string `json:"type"`
Required bool `json:"required"` Required bool `json:"required"`
Min interface{} `json:"min,omitempty"` Min interface{} `json:"min,omitempty"`
Max interface{} `json:"max,omitempty"` Max interface{} `json:"max,omitempty"`
Pattern string `json:"pattern,omitempty"` Pattern string `json:"pattern,omitempty"`
CustomRule string `json:"custom_rule,omitempty"` Expression string `json:"expression,omitempty"` // For custom expressions
Message string `json:"message,omitempty"` CustomRule string `json:"custom_rule,omitempty"`
Conditions []ConditionConfig `json:"conditions,omitempty"` Message string `json:"message,omitempty"`
Config map[string]interface{} `json:"config,omitempty"`
Conditions []ConditionConfig `json:"conditions,omitempty"`
} }
// Provider configuration for SMS/communication services // Generic runtime types for the JSON engine
type ProviderConfig struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"` // "sms", "email", "push"
Enabled bool `json:"enabled"`
Priority int `json:"priority"`
Config map[string]interface{} `json:"config"`
Countries []string `json:"countries,omitempty"`
RateLimit *RateLimitConfig `json:"rate_limit,omitempty"`
Costs map[string]float64 `json:"costs,omitempty"`
Features []string `json:"features,omitempty"`
Reliability float64 `json:"reliability"`
}
// RateLimitConfig defines rate limiting
type RateLimitConfig struct {
RequestsPerSecond int `json:"requests_per_second"`
BurstSize int `json:"burst_size"`
WindowSize int `json:"window_size"`
}
// Country configuration for routing
type CountryConfig struct {
Code string `json:"code"`
Name string `json:"name"`
Providers []string `json:"providers"`
DefaultRate float64 `json:"default_rate"`
Regulations map[string]string `json:"regulations,omitempty"`
}
// Runtime types for the JSON engine
type JSONEngine struct { type JSONEngine struct {
app *fiber.App app *fiber.App
workflowEngine *workflow.WorkflowEngine workflowEngine *workflow.WorkflowEngine
config *AppConfiguration workflowEngineConfig *WorkflowEngineConfig
templates map[string]*Template config *AppConfiguration
workflows map[string]*Workflow templates map[string]*Template
functions map[string]*Function workflows map[string]*Workflow
validators map[string]*Validator functions map[string]*Function
middleware map[string]*Middleware validators map[string]*Validator
data map[string]interface{} middleware map[string]*Middleware
data map[string]interface{}
genericData map[string]interface{} // For any custom data structures
} }
type Template struct { type Template struct {
@@ -303,16 +300,20 @@ type Edge struct {
To *Node To *Node
} }
// Function represents a compiled function with generic handler
type Function struct { type Function struct {
ID string ID string
Config FunctionConfig Config FunctionConfig
Handler interface{} Handler interface{} // Can be any type of handler
Runtime map[string]interface{} // Runtime state/context
} }
// Validator represents a compiled validator with generic rules
type Validator struct { type Validator struct {
ID string ID string
Config ValidatorConfig Config ValidatorConfig
Rules []ValidationRule Rules map[string]interface{} // Generic rules instead of typed array
Runtime map[string]interface{} // Runtime context
} }
type Middleware struct { type Middleware struct {
@@ -328,7 +329,7 @@ type WorkflowRuntime struct {
Error error Error error
} }
// Execution context for runtime // ExecutionContext for runtime with complete flexibility
type ExecutionContext struct { type ExecutionContext struct {
Request *fiber.Ctx Request *fiber.Ctx
Data map[string]interface{} Data map[string]interface{}
@@ -339,4 +340,7 @@ type ExecutionContext struct {
Node *Node Node *Node
Functions map[string]*Function Functions map[string]*Function
Validators map[string]*Validator Validators map[string]*Validator
Config *AppConfiguration // Access to full config
Runtime map[string]interface{} // Runtime state
Context map[string]interface{} // Additional context data
} }

Binary file not shown.