Skip to content

Instantly share code, notes, and snippets.

@bendauphinee
Created March 5, 2016 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendauphinee/862ed8399b8a50959858 to your computer and use it in GitHub Desktop.
Save bendauphinee/862ed8399b8a50959858 to your computer and use it in GitHub Desktop.
A golang HTTP beacon script, with debug
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