Skip to content

Instantly share code, notes, and snippets.

@wilk
Last active November 7, 2017 07:47
Show Gist options
  • Save wilk/f2c1ba12d8bd1eda1d65aa5e504a39a8 to your computer and use it in GitHub Desktop.
Save wilk/f2c1ba12d8bd1eda1d65aa5e504a39a8 to your computer and use it in GitHub Desktop.
Goxfer
package main
import (
"fmt"
"os"
"errors"
"github.com/parnurzeal/gorequest"
)
type LoginResponse struct {
Response struct {
Status string `json:"status"`
Token string `json:"token"`
} `json:"response"`
}
var (
BUXFER_API_URL = os.Getenv("BUXFER_API_ENDPOINT")
BUXFER_USERNAME = os.Getenv("BUXFER_USERNAME")
BUXFER_PASSWORD = os.Getenv("BUXFER_PASSWORD")
)
func main() {
fmt.Println("Creating session for Buxfer...")
var result LoginResponse
request := gorequest.New()
res, _, errs := request.Get(BUXFER_API_URL + "/login").
Query("userid=" + BUXFER_USERNAME).
Query("password=" + BUXFER_PASSWORD).
EndStruct(&result)
if len(errs) > 0 {
panic(errs)
}
if res.StatusCode > 399 {
panic(res.Status)
}
if result.Response.Status != "OK" || len(result.Response.Token) == 0 {
panic(errors.New("An error occured during the Buxfer's login"))
}
token := result.Response.Token
fmt.Println("Buxfer session created!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment