Skip to content

Instantly share code, notes, and snippets.

@rebeccaskinner
Created April 16, 2017 00:10
Show Gist options
  • Save rebeccaskinner/44d3418ecd1e9dc875beb2ef7bdd075a to your computer and use it in GitHub Desktop.
Save rebeccaskinner/44d3418ecd1e9dc875beb2ef7bdd075a to your computer and use it in GitHub Desktop.
func main() {
config, err := getArgs()
if err != nil {
fmt.Println(err)
fmt.Println(showHelp())
os.Exit(1)
}
var (
getEndpoint = fmt.Sprintf("%s/oldusers/%s", config.endpoint, config.username)
postEndpoint = fmt.Sprintf("%s/newusers/%s", config.endpoint, config.username)
get = either.WrapEither(http.Get)
)
result := get(getEndpoint).
Next(getResponseBody).
Next(ioutil.ReadAll).
Next(user.NewFromJSON).
Next(user.NewUserFromUser).
Next(json.Marshal).
Next(bytes.NewBuffer).
Next(func(b *bytes.Buffer) (*http.Response, error) {
return http.Post(postEndpoint, "application/json", b)
})
fmt.Println(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment