Created
December 30, 2017 00:02
-
-
Save picatz/01d7b59acd3747c46ce257d4846a1e59 to your computer and use it in GitHub Desktop.
Falcon Sandbox Public API v1.1 Example Golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
type APIKeyData struct { | |
ResponseCode int `json:"response_code"` | |
Response APIKeyDataResponse `json:"response"` | |
} | |
type APIKeyDataResponse struct { | |
Key string `json:"api_key"` | |
AuthLevel int `json:"auth_level"` | |
AuthLevelName string `json:"auth_level_name"` | |
User APIKeyDataResponseUser | |
} | |
type APIKeyDataResponseUser struct { | |
Name string `json:"name"` | |
Email string `json:"email"` | |
Id string `json:"_id"` | |
} | |
func main() { | |
req, err := http.NewRequest("GET", "https://www.hybrid-analysis.com/api/get-api-key-data", nil) | |
if err != nil { | |
// handle err | |
log.Println(err) | |
} | |
req.SetBasicAuth(os.ExpandEnv("$HYBRID_ANALYSIS_API_KEY"), os.ExpandEnv("$HYBRID_ANAYLSIS_API_SECRET")) | |
req.Header.Add("User-Agent", "picat-loves-you (https://picatz.github.io)") | |
resp, err := http.DefaultClient.Do(req) | |
if err != nil { | |
// handle err | |
log.Println(err) | |
} | |
defer resp.Body.Close() | |
var data APIKeyData | |
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { | |
// handle err | |
log.Println(err) | |
} | |
fmt.Println("API Key:", data.Response.Key) | |
fmt.Println("Auth Level:", data.Response.AuthLevel) | |
fmt.Println("Auth Level Name:", data.Response.AuthLevelName) | |
fmt.Println("User Name:", data.Response.User.Name) | |
fmt.Println("User E-mail:", data.Response.User.Email) | |
fmt.Println("User ID:", data.Response.User.Id) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment