Skip to content

Instantly share code, notes, and snippets.

@nrshrivatsan
Last active August 29, 2015 14:23
Show Gist options
  • Save nrshrivatsan/35d5ca1342981ee6e593 to your computer and use it in GitHub Desktop.
Save nrshrivatsan/35d5ca1342981ee6e593 to your computer and use it in GitHub Desktop.
Minor Load script on ETCD
package main
import (
"fmt"
"net/http"
"io/ioutil"
"bytes"
"strconv"
"math/rand"
)
func hitETCD(value string) {
//ETCD Keys endpoint
endpoint := "http://127.0.0.1:2379/v2/keys/"
var jsonStr = []byte(value)
//HTTP POST method
req, err := http.NewRequest("POST", endpoint+strconv.Itoa(rand.Intn(200)), bytes.NewBuffer(jsonStr))
client := &http.Client{}
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() {
// fmt.Println("URL:>", url)
limit := 900000
for i := 0; i < limit; i++ {
//Spawning an independent goroutine to make HTTP get calls
// go hitETCD(`{"value":"Hello World this is ETCD load script"}`)
hitETCD(`{"value":"New value"+strconv.Itoa(i)}`)
}
}
@nrshrivatsan
Copy link
Author

NOTE - Need to make go channels and MAX PROC changes if need be.

@nrshrivatsan
Copy link
Author

Hit http://localhost:2379/v2/keys to view the keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment