๐Ÿน @ Operator System in TuskLang - Go Guide

Go Documentation

@ 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.