Skip to content

Commit

Permalink
docs: explain that dual import is not recommended
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Egan <charlie@styra.com>
  • Loading branch information
charlieegan3 committed Dec 17, 2024
1 parent 297cf7a commit cfb4299
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions docs/content/v0-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ r := rego.New(
)
```

Finally, another option is to import the `v0` package instead. This can even be
used alongside the `v1` package in the same program if required. The program
below will evaluate the same Rego using both the v0 and v1 Rego packages, v1 is
running in v0 compatibility mode with `SetRegoVersion`:
Finally, another option is to import the `v0` package instead. The program
below imports the v0 package instead:

```go
package main
Expand All @@ -128,30 +126,17 @@ import (
"fmt"

v0rego "github.com/open-policy-agent/opa/rego"
v1ast "github.com/open-policy-agent/opa/v1/ast"
v1rego "github.com/open-policy-agent/opa/v1/rego"
// v1rego "github.com/open-policy-agent/opa/v1/rego"
)

func main() {
// we have a v0 Rego module, we want to evaluate it using the v1 rego
// package and the v0 rego package in the same program.
module := `package example
messages[msg] {
msg := "foo"
}
`

rv1 := v1rego.New(
v1rego.Query("data.example.messages"),
v1rego.SetRegoVersion(v1ast.RegoV0),
v1rego.Module("example.rego", module),
)

rs, _ := rv1.Eval(context.TODO())
bs, _ := json.Marshal(rs)
fmt.Println(string(bs))

rv0 := v0rego.New(
v0rego.Query("data.example.messages"),
v0rego.Module("example.rego", module),
Expand All @@ -164,6 +149,11 @@ messages[msg] {
}
```

{{< danger >}}
**Note**: Using v0 packages and v1 packages in the same program is not
recommended. Interoperability between the two packages is not guaranteed.
{{< /danger >}}

### v0.x compatibility mode in the OPA Go SDK

{{< info >}}
Expand Down

0 comments on commit cfb4299

Please sign in to comment.