dospin/dospin.go

53 lines
1.1 KiB
Go
Raw Normal View History

2016-02-26 17:35:57 -06:00
/*
Copyright 2016 gtalent2@gmail.com
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
2016-02-14 23:38:28 -06:00
package main
import (
"github.com/digitalocean/godo"
"golang.org/x/oauth2"
"log"
)
type TokenSource struct {
AccessToken string
}
func (t *TokenSource) Token() (*oauth2.Token, error) {
token := &oauth2.Token{
AccessToken: t.AccessToken,
}
return token, nil
}
func main() {
settings, err := loadSettings("dospin.json")
if err != nil {
log.Fatal(err)
}
tokenSource := &TokenSource{settings.Token}
oauthClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
client := godo.NewClient(oauthClient)
dm := NewDropletManager(client, settings)
ip, err := dm.SpinupMachine("minecraft")
2016-02-14 23:38:28 -06:00
if err != nil {
log.Println("Error:", err)
2016-02-14 23:38:28 -06:00
return
}
log.Println("IP: " + ip)
if err := dm.SpindownMachine("minecraft"); err != nil {
log.Println("Error:", err)
return
}
2016-02-15 00:18:56 -06:00
//_, err = client.Droplets.Delete(droplet.ID)
//if err != nil {
// log.Println(err)
//}
2016-02-14 23:38:28 -06:00
}