mirror of
https://codeberg.org/ultimateplayer1999/go-api-usage.git
synced 2024-11-22 15:48:20 -05:00
48 lines
906 B
Go
48 lines
906 B
Go
|
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))
|
||
|
|
||
|
}
|