On branch golang-master
Changes to be committed: new file: main.go Basic url construction working
This commit is contained in:
parent
5d64335135
commit
202814d46c
40
main.go
Normal file
40
main.go
Normal file
@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"encoding/json"
|
||||
/*
|
||||
"fmt"
|
||||
*/
|
||||
)
|
||||
|
||||
/*droplet_api := io.Post("")
|
||||
*/
|
||||
|
||||
func main() {
|
||||
url_slice := []string{"https://api.digitalocean.com/v2/droplets/", get_droplet_id("foo"), "/actions"}
|
||||
droplet_actions_url := strings.Join(url_slice, "")
|
||||
post_body, _ := json.Marshal(map[string]string{"type": "power_off"})
|
||||
response_body := bytes.NewBuffer(post_body)
|
||||
http_response, err := http.Post(droplet_actions_url, "application/json", response_body)
|
||||
if err != nil {
|
||||
log.Fatalf("Respones Error: %v", err)
|
||||
}
|
||||
defer http_response.Body.Close()
|
||||
body, err := ioutil.ReadAll(response_body)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
response_body_string := string(body)
|
||||
log.Printf(response_body_string)
|
||||
}
|
||||
|
||||
func get_droplet_id(hostname string) string {
|
||||
// var droplet_id string = "253365345"
|
||||
var droplet_id string = "253365347"
|
||||
return droplet_id
|
||||
}
|
Loading…
Reference in New Issue
Block a user