How kmesiab/go-policy-enforcer works
Project type and purpose
• This is a Go-based library (not a standalone app) whose sole purpose is to let other Go programs apply “policies” (sets of field-based rules) to arbitrary Go structs at runtime. It is packaged for reuse, extensibility (custom operators), and reflection-driven evaluation.
File structure
• Top level:
• core API files: policy.go, rule.go, policy_enforcer.go, evaluator.go
• operator definitions: operators.go, operators_map.go
• custom extensions: custom_operators/
• internal utilities: internal/utils/
• examples: examples/* (show usage scenarios)
• CI/CD: .github/workflows/*.yml
• Patterns and choices:
• Registry pattern for operators (operators_map.go)
• Reflection (evaluator.go) to walk dot-notation fields
• Extensibility via pluggable operator implementations
• Example JSON policy files (examples/json_policy_example/)
README for additional insights
• Confirms: dynamic enforcement, reflection, custom operators, JSON policy file support, Enforce vs. Match APIs, nested struct support.