-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (30 loc) · 870 Bytes
/
main.go
File metadata and controls
37 lines (30 loc) · 870 Bytes
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
package main
import (
"encoding/json"
"fmt"
"github.com/extism/go-pdk"
)
//export validate_data
func validate_data() int32 {
// Read the input JSON string from the host
input_string := pdk.InputString()
var data map[string]interface{}
err := json.Unmarshal([]byte(input_string), &data)
if err != nil {
// Return error message if JSON is invalid
error_msg := fmt.Sprintf(`{"valid": false, "error": "invalid JSON: %s"}`, err.Error())
pdk.OutputString(error_msg)
return 1 // Indicate failure
}
// Check if the "signature" key exists
if _, ok := data["signature"]; !ok {
error_msg := `{"valid": false, "error": "missing 'signature' key"}`
pdk.OutputString(error_msg)
return 1 // Indicate failure
}
// If validation is successful
success_msg := `{"valid": true}`
pdk.OutputString(success_msg)
return 0 // Indicate success
}
func main() {}