-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
79 lines (63 loc) · 1.77 KB
/
Copy pathexample_test.go
File metadata and controls
79 lines (63 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package evervault_test
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"github.com/evervault/evervault-go"
)
// Full Example encrypting data and using outbound relay to talk to a third party.
func Example() {
syntheticEndpointUrl := os.Getenv("EV_SYNTHETIC_ENDPOINT_URL")
evClient, err := evervault.MakeClient(os.Getenv("EV_APP_UUID"), os.Getenv("EV_API_KEY"))
if err != nil {
log.Fatal(err)
}
encrypted, err := evClient.EncryptString("Hello, world!")
if err != nil {
log.Fatal(err)
}
fmt.Println(encrypted[0:3]) // Only print start of string to indicate its encrypted
// Send the decrypted data to a third-party API
outboundRelayClient, err := evClient.OutboundRelayClient()
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
data := map[string]string{"string": "value"}
payload, err := json.Marshal(data)
if err != nil {
log.Fatalf("Encountered unexpected error: %s", err)
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost, syntheticEndpointUrl, bytes.NewReader(payload))
if err != nil {
log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
resp, err := outboundRelayClient.Do(req)
if err != nil {
log.Fatal(err)
}
defer func() {
bodyCloseErr := resp.Body.Close()
if bodyCloseErr != nil {
log.Printf("Failed to close response body: %s", bodyCloseErr)
}
}()
fmt.Println(resp.Status)
}
// Example encrypting data locally.
func ExampleClient_EncryptString() {
evClient, err := evervault.MakeClient(os.Getenv("EV_APP_UUID"), os.Getenv("EV_API_KEY"))
if err != nil {
log.Fatal(err)
}
encrypted, err := evClient.EncryptString("Hello, world!")
if err != nil {
log.Fatal(err)
}
fmt.Println(encrypted[0:3]) // Only print start of string to indicate its encrypted
}