-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLanguages.go
45 lines (37 loc) · 977 Bytes
/
Languages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/url"
"os"
)
func main() {
if "" == os.Getenv("TRANSLATOR_TEXT_ENDPOINT") {
log.Fatal("Please set/export the environment variable TRANSLATOR_TEXT_ENDPOINT.")
}
endpoint := os.Getenv("TRANSLATOR_TEXT_ENDPOINT")
uri := endpoint + "/languages?api-version=3.0"
getLanguages(uri)
}
func getLanguages(uri string) {
u, _ := url.Parse(uri)
q := u.Query()
u.RawQuery = q.Encode()
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
log.Fatal(err)
}
req.Header.Add("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
var result interface{}
if err := json.NewDecoder(res.Body).Decode(&result); err != nil {
log.Fatal(err)
}
prettyJSON, _ := json.MarshalIndent(result, "", " ")
fmt.Printf("%s\n", prettyJSON)
}