docs/projects/regal/integration.md
:warning: Using Regal from Go is currently experimental and subject to change. Please swing by Slack if you're keen to use Regal in a production system.
If you'd like to integrate Regal into a Go application, this guide contains some pointers.
Regal can be used from a Go application by importing the linter package:
import "github.com/open-policy-agent/regal/pkg/linter"
Input to Lint can be provided in a number of ways:
InputFromPaths helper to load Rego files from the filesystem,InputFromText helper to parse a single Rego module from a string,InputFromPathspaths := []string{"foo.rego", "bar.rego"}
input, err := rules.InputFromPaths(paths)
if err != nil {
// handle error
}
InputFromText
regoText := `package foo...`
input, err := rules.InputFromText("policy.rego", regoText)
if err != nil {
// handle error
}
To get a Regal report back for the provided input, create a Regal instance and call Lint:
regalInstance := linter.NewLinter().WithInputModules(&input)
lintingReport, err := regalInstance.Lint(r.Context())
if err != nil {
response.ErrorMessage = err.Error()
writeJSON(w, http.StatusOK, response)
return
}