Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add v0 import example to v0-compatibility #8

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions docs/content/v0-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,48 @@ r := rego.New(
)
```

Finally, another option is to import the `v0` package instead. The program

below imports the v0 package instead:

```go
package main

import (
"context"
"encoding/json"
"fmt"

"github.com/open-policy-agent/opa/rego"
// rather than the v1 import, which is:
// "github.com/open-policy-agent/opa/v1/rego"
)

func main() {
module := `package example
messages[msg] {
msg := "foo"
}
`

r := v0rego.New(
rego.Query("data.example.messages"),
rego.Module("example.rego", module),
)

rs, _ = rv0.Eval(context.TODO())
bs, _ = json.Marshal(rs)

fmt.Println(string(bs))
}
```

{{< danger >}}
**Note**: Using v0 packages and v1 packages in the same program is considered an
anti-pattern and is not recommended or supported. Any interoperability between
the two packages is not guaranteed and should be considered unsupported.
{{< /danger >}}

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

{{< info >}}
Expand Down
Loading