๐น @ Operator System in TuskLang - Go Guide
@ Operator System in TuskLang - Go Guide
โก๏ธ The Power of @: Operators Unleashed
TuskLangโs @ operator system is pure rebellionโdynamic, extensible, and ready for anything. This guide gives Go developers a complete overview of @ operators, usage patterns, and best practices for integrating them into your Go projects.
๐ Table of Contents
- What Are @ Operators? - Core Operator Types - Usage Patterns - Go Integration - Best Practices๐ค What Are @ Operators?
@ operators are TuskLangโs superpower: they inject dynamic logic, real-time data, and external integrations directly into your config. No more static filesโ@ operators make your config come alive.
๐งฉ Core Operator Types
- @env
โ Environment variables
- @date
โ Date/time operations
- @query
โ Database queries
- @cache
โ Caching
- @metrics
โ Metrics and monitoring
- @file
โ File operations
- @http
โ HTTP requests
- @encrypt
โ Encryption
- @validate
โ Validation
- @learn
โ Machine learning
๐ ๏ธ Usage Patterns
Environment Variables
[api]
api_key: @env("API_KEY", "default")
Database Queries
[stats]
user_count: @query("SELECT COUNT(*) FROM users")
Caching
[metrics]
user_count: @cache("5m", @query("SELECT COUNT(*) FROM users"))
Date/Time
[build]
build_time: @date.now()
HTTP Requests
[external]
status: @http("GET", "https://api.example.com/status")
๐ Go Integration
Accessing Operator Values
val, err := config.GetString("api_key") // Handles @env
count, err := config.GetInt("user_count") // Handles @query/@cache
Custom Operator Handling
type CustomOperator struct {
Name string
Eval func(args ...interface{}) (interface{}, error)
}func RegisterOperator(name string, eval func(args ...interface{}) (interface{}, error)) {
tusklang.RegisterOperator(name, eval)
}
// Example: Register a custom operator
RegisterOperator("shout", func(args ...interface{}) (interface{}, error) {
if len(args) == 0 { return "", nil }
return strings.ToUpper(fmt.Sprint(args[0])), nil
})
๐ฅ Best Practices
- Use @ operators for all dynamic config needs - Validate operator results at runtime - Register custom operators for project-specific logic - Document all operator usage in your config
---
TuskLang: With @ operators, your config is alive.