Created
January 16, 2018 14:57
-
-
Save eoinahern/ac61458fa77e0f7f0c8dec1244b19413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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