type UserDictionaryEntry struct {
FromLang string `json:"fromLang"`
FromText string `json:"fromText"`
ToLang string `json:"toLang"`
ToText string `json:"toText"`
}
func AddUserDictionaryEntry(basePath string) {
apiURL := "/api/v1/dictionary"
requestJson := &UserDictionaryEntry{
FromLang: "en",
FromText: "square",
ToLang: "jp",
ToText: "広場"}
jsonValue, _ := json.Marshal(requestJson)
client := &http.Client{}
req, err := http.NewRequest(
"POST",
GetFullUrl(basePath, apiURL),
bytes.NewBuffer([]byte(jsonValue)),
)
req.Header.Set("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Printf("The HTTP request failed with error %s\n", err)
} else {
data, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(data))
}
}