go-api-examples/containertime.go

48 lines
906 B
Go
Raw Normal View History

2023-01-10 09:57:26 -05:00
package main
import (
"net/http"
"log"
"fmt"
"os"
"io/ioutil"
"github.com/joho/godotenv"
)
func main() {
// Load environment variables from .env file
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
token := os.Getenv("TOKEN")
// Make an HTTP request to api.discord-linux.com
req, err := http.NewRequest("GET", "https://api.discord-linux.com/time", nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("Accept", "application/json")
req.Header.Add("Content-Type", "Application/json")
req.Header.Add("x-discord-linux-auth", token)
client := http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
fmt.Println("Status code: ", resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
}