Files
Charlie Egan ad1c5e71ae website: Use Regal in regal page titles (#8033)
Rather than Open Policy Agent, which was confusing

Signed-off-by: Charlie Egan <charlie_egan@apple.com>
2025-11-10 12:39:23 +00:00

1.4 KiB

sidebar_position, sidebar_label
sidebar_position sidebar_label
12 Go Integration
<head> </head>

Go Integration

⚠️ 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.

Using Regal from Go

Regal can be used from a Go application by importing the linter package:

import "github.com/open-policy-agent/regal/pkg/linter"

Input

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,

Using InputFromPaths

paths := []string{"foo.rego", "bar.rego"}

input, err := rules.InputFromPaths(paths)
if err != nil {
    // handle error
}

Using InputFromText


regoText := `package foo...`

input, err := rules.InputFromText("policy.rego", regoText)
if err != nil {
    // handle error
}

Linting

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
}