Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Example ¶
package main
import (
"context"
"fmt"
"os"
"testing"
opaclient "github.com/m-mizutani/opa-go-client"
"github.com/stretchr/testify/require"
)
func main() {
client, err := opaclient.New("http://localhost:8181")
if err != nil {
panic(err)
}
req := opaclient.DataRequest{
Path: "example/policy",
Input: map[string]string{
"user": "m-mizutani",
},
}
resp := struct {
Allowed bool `json:"allowed"`
}{}
if err := client.GetData(context.Background(), &req, &resp); err != nil {
panic(err)
}
fmt.Println("allowed? =>", resp.Allowed)
}
func setupClient(t *testing.T) *opaclient.Client {
url, ok := os.LookupEnv("OPA_BASE_URL")
if !ok {
t.Skip("OPA_BASE_URL is not set")
}
client, err := opaclient.New(url)
require.NoError(t, err)
return client
}
Output:
type DataRequest ¶
type DataRequest struct {
Input interface{}
Path string
}
type Option ¶
func WithHTTPClient ¶
func WithHTTPClient(httpClient HTTPClient) Option
Click to show internal directories.
Click to hide internal directories.