Skip to content

Instantly share code, notes, and snippets.

@elboletaire
Created August 22, 2024 15:25
Show Gist options
  • Save elboletaire/9be8551445bdb3ea3398c5cfce7148bb to your computer and use it in GitHub Desktop.
Save elboletaire/9be8551445bdb3ea3398c5cfce7148bb to your computer and use it in GitHub Desktop.
const validateFrameEndpoint = "https://hubs.airstack.xyz/v1/validateMessage"
func ValidateFrameMessage(msg []byte) map[string]interface{} {
req, err := http.NewRequest(http.MethodPost, validateFrameEndpoint, bytes.NewBuffer(msg))
if err != nil {
log.Warn("error creating request:", err)
return nil
}
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Warn("error sending request:", err)
return nil
}
airstackResponse := make(map[string]interface{})
if err := json.NewDecoder(res.Body).Decode(&airstackResponse); err != nil {
log.Warn("error decoding response:", err)
return nil
}
if res.StatusCode != http.StatusOK {
log.Warn("unexpected status code:", res.StatusCode)
return nil
}
isValid, ok := airstackResponse["isValid"]
if !ok {
log.Warn("isValid field missing in response")
return nil
}
if valid, ok := isValid.(bool); !ok || !valid {
log.Warn("invalid frame message")
return nil
}
return airstackResponse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment