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/styrainc/regal/pkg/linter"
Input to Lint
can be provided in a number of ways:
- Using the
InputFromPaths
helper to load Rego files from the filesystem, - Using the
InputFromText
helper to parse a single Rego module from a string,
paths := []string{"foo.rego", "bar.rego"}
input, err := rules.InputFromPaths(paths)
if err != nil {
// handle error
}
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
}
If you'd like to discuss Regal development or just talk about Regal in general, please join us in the #regal
channel in the Styra Community Slack!