Random Name API for Go.
Clean example request for the random name feature endpoint. Replace YOUR API and amount input, then run the code.
Checking
Clean example request for the random name feature endpoint. Replace YOUR API and amount input, then run the code.
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
const (
apiKey = "YOUR API"
jumlah = int
endpoint = "https://senpai-bot.store/randomname"
)
type ApiResponse struct {
Code int `json:"code"`
Result []string `json:"result"`
}
func main() {
url := fmt.Sprintf("%s?apikey=%s&num=%d", endpoint, apiKey, jumlah)
resp, err := http.Get(url)
if err != nil {
fmt.Println("Gagal request:", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Printf("Kode HTTP error: %d\n", resp.StatusCode)
return
}
var result ApiResponse
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
fmt.Println("Gagal parsing JSON:", err)
return
}
if result.Code != 200 {
fmt.Printf("API error code: %d\n", result.Code)
return
}
if len(result.Result) == 0 {
fmt.Println("Tidak ada hasil ditemukan.")
return
}
fmt.Println("Hasil nama acak:")
for _, nama := range result.Result {
fmt.Println(nama)
}
}