Skip to content

Instantly share code, notes, and snippets.

@marshallmassengill
Last active June 19, 2017 13:25
Show Gist options
  • Save marshallmassengill/cf171fb0c02958da5a8e4938ebbde8a7 to your computer and use it in GitHub Desktop.
Save marshallmassengill/cf171fb0c02958da5a8e4938ebbde8a7 to your computer and use it in GitHub Desktop.
HTTP Server for HID RFID Reader to vRealize Operations
package main
import (
"fmt"
"log"
"net/http"
"bytes"
"io/ioutil"
"crypto/tls"
)
type hidHandler struct{}
func (h hidHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
fmt.Fprintf(w, "GET params were: ", r.URL.Query());
serial := r.URL.Query().Get("serial")
if serial != ""{
fmt.Println(serial);
//Send the request to vRO
url := "https://192.168.42.181:8281/vco/api/workflows/21489dd7-6602-4aa8-b3dc-b70e50076372/executions"
fmt.Println("URL:>", url)
var jsonStr = []byte(`{"parameters":[{"value": {"string":{ "value": "` + serial + `"}},"type": "string","name": "serial","scope": "local"}]}`)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.SetBasicAuth("vcoadmin", "vcoadmin")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{Transport: tr}
resp, err := client.Do(req)
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))
}
}
func main() {
err := http.ListenAndServe(":80", hidHandler{})
log.Fatal(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment