Random Pict API for Go.
Clean example request for the random picture feature endpoint. Replace YOUR API and amount input, then run the code.
Checking
Clean example request for the random picture feature endpoint. Replace YOUR API and amount input, then run the code.
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
)
const (
APIKey = "YOUR API"
Jumlah = int
Endpoint = "https://senpai-bot.store/randompict"
)
func main() {
fullURL := fmt.Sprintf("%s?apikey=%s&num=%d", Endpoint, APIKey, Jumlah)
resp, err := http.Get(fullURL)
if err != nil {
fmt.Println("Gagal request:", err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println("Gagal membaca response:", err)
return
}
var data struct {
Code int `json:"code"`
Message string `json:"message"`
Result []string `json:"result"`
}
if err := json.Unmarshal(body, &data); err != nil {
fmt.Println("Gagal parsing JSON:", err)
return
}
if data.Code != 200 {
fmt.Printf("API error code: %d - %s\n", data.Code, data.Message)
return
}
if len(data.Result) > 0 {
fmt.Println("Hasil gambar:")
for _, url := range data.Result {
fmt.Println(url)
}
} else {
fmt.Println("Tidak ada hasil ditemukan.")
}
}