Skip to content

Instantly share code, notes, and snippets.

@eoinahern
Created January 16, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eoinahern/ac61458fa77e0f7f0c8dec1244b19413 to your computer and use it in GitHub Desktop.
Save eoinahern/ac61458fa77e0f7f0c8dec1244b19413 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
"os"
)
type Episode struct {
PodID uint `json:"podid"`
Created string `json:"created" `
Updated string `json:"updated" `
URL string `json:"url"`
Downloads int32 `json:"downloads" `
Blurb string `json:"blurb"`
Data os.File `json:"data" `
}
func main() {
myfile, err := os.Create("./blah.txt")
episode := Episode{
PodID: 5,
Created: "stuff",
Updated: "stuff",
URL: "stuff",
Blurb: "a blurb",
Data: *myfile,
}
var buf bytes.Buffer
err = json.NewEncoder(&buf).Encode(episode)
if err != nil {
log.Fatal(err)
}
client := http.Client{}
req, err := http.NewRequest(http.MethodPost, "http://localhost:8080/upload", &buf)
req.Header.Set("Content-Type", "application/json")
if err != nil {
log.Println(err)
}
client.Do(req)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment