Created
March 5, 2016 17:24
-
-
Save bendauphinee/862ed8399b8a50959858 to your computer and use it in GitHub Desktop.
A golang HTTP beacon script, with debug
This file contains 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" | |
"io/ioutil" | |
"net/http" | |
"os" | |
//https://github.com/davecgh/go-spew | |
//"go-spew/spew" | |
) | |
func main() { | |
// Load the config from file | |
thisConfig := loadConfig() | |
//spew.Dump(thisConfig) | |
fmt.Println("URL:>", thisConfig.BeaconUrl) | |
resp, err := http.Get(thisConfig.BeaconUrl) | |
if err != nil { | |
panic(err) | |
} | |
defer resp.Body.Close() | |
fmt.Println("Response Status:", resp.Status) | |
fmt.Println("Response Headers:", resp.Header) | |
body, _ := ioutil.ReadAll(resp.Body) | |
fmt.Println("Response Body:", string(body)) | |
} | |
type ConfigVars struct { | |
BeaconUrl string `json:"beaconUrl"` | |
} | |
/** | |
* This function loads a config file up. | |
*/ | |
func loadConfig() ConfigVars { | |
configFile, err := os.Open("beaconConfig.json") | |
defer configFile.Close() | |
if err != nil { | |
fmt.Println("Opening config file", err.Error()) | |
} | |
var thisConfig ConfigVars | |
jsonParser := json.NewDecoder(configFile) | |
if err = jsonParser.Decode(&thisConfig); err != nil { | |
fmt.Println("Parsing config file", err.Error()) | |
} | |
return thisConfig | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment