examples

command
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 3 Imported by: 0

README ¶

Examples - Go Rules Engine

Ce dossier contient des exemples d'utilisation du moteur de règles Go.

📚 Exemples disponibles

1. basic/main.go

Exemple basique - Vérification d'âge simple avec une seule règle.

go run examples/basic/main.go

Démontre :

  • âś… CrĂ©ation d'un engine
  • âś… Règle simple avec condition
  • âś… OpĂ©rateur greater_than
  • âś… Tests avec diffĂ©rentes valeurs
2. json/main.go

Chargement JSON - Charge des règles et facts depuis JSON.

go run examples/json/main.go

Démontre :

  • âś… Unmarshal de règles JSON
  • âś… Unmarshal de facts JSON
  • âś… Ajout de règles Ă  l'engine
  • âś… Ajout de facts Ă  l'almanac
  • âś… Règles VIP et rĂ©gulières
3. custom-operator/main.go

Opérateurs personnalisés - Création d'opérateurs custom.

go run examples/custom-operator/main.go

Démontre :

  • âś… Interface Operator
  • âś… ImplĂ©mentation de CustomOperator
  • âś… OpĂ©rateurs starts_with, ends_with, between
  • âś… RegisterOperator pour enregistrer les opĂ©rateurs
4. advanced/main.go

Fonctionnalités avancées - Callbacks, handlers et dynamic facts.

go run examples/advanced/main.go

Démontre :

  • âś… Callbacks nommĂ©s avec RegisterCallback
  • âś… Handler global OnSuccess
  • âś… Handler spĂ©cifique par type d'Ă©vĂ©nement On()
  • âś… Dynamic facts (calcul de remise)
  • âś… Multiple handlers simultanĂ©s
5. full-demo.go

Démonstration complète - Toutes les fonctionnalités en un seul exemple.

go run examples/full-demo.go

Démontre :

  • âś… Règles simples et complexes
  • âś… Conditions imbriquĂ©es (all/any)
  • âś… Callbacks et handlers
  • âś… Chargement JSON
  • âś… Dynamic facts
  • âś… JSONPath
  • âś… Historique des Ă©vĂ©nements

🚀 Exécution

Depuis la racine du projet :

# Exemple basique
go run examples/basic/main.go

# JSON
go run examples/json/main.go

# Custom operators
go run examples/custom-operator/main.go

# Advanced
go run examples/advanced/main.go

# Full demo
go run examples/full-demo.go

📖 Documentation complète

Voir le README principal pour la documentation complète de l'API.

đź’ˇ Quick Start

Pour créer votre propre application :

  1. Import :

    import gorulesengine "github.com/deadelus/go-rules-engine/src"
    
  2. Engine :

    engine := gorulesengine.NewEngine()
    
  3. Règle :

    rule := &gorulesengine.Rule{
        Name:     "my-rule",
        Priority: 100,
        Conditions: gorulesengine.ConditionSet{
            All: []gorulesengine.ConditionNode{
                {
                    Condition: &gorulesengine.Condition{
                        Fact:     "age",
                        Operator: "greater_than",
                        Value:    18,
                    },
                },
            },
        },
        Event: gorulesengine.Event{
            Type: "adult",
        },
    }
    engine.AddRule(rule)
    
  4. Almanac :

    almanac := gorulesengine.NewAlmanac([]*gorulesengine.Fact{})
    almanac.AddFact("age", 25)
    
  5. Run :

    results, err := engine.Run(almanac)
    if err != nil {
        log.Fatal(err)
    }
    
    for _, result := range results {
        if result.Result {
            fmt.Printf("âś… %s\n", result.Event.Type)
        }
    }
    

📝 Structure des exemples

examples/
├── README.md           # Ce fichier
├── full-demo.go        # Démo complète
├── basic/              # Exemple basique
│   └── main.go
├── json/               # Chargement JSON
│   └── main.go
├── custom-operator/    # Opérateurs custom
│   └── main.go
└── advanced/           # Features avancées
    └── main.go

Consultez chaque exemple pour des cas d'usage spécifiques!

Documentation ¶

The Go Gopher

There is no documentation for this package.

Directories ¶

Path Synopsis

Jump to

Keyboard shortcuts

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