58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
|
_ "github.com/joho/godotenv/autoload"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
// Define the request context with essential information.
|
|
requestContext := model.RequestContext{
|
|
Client: http.Client{},
|
|
Host: "https://e621.net",
|
|
UserAgent: "Go-e621-SDK (@username)",
|
|
Username: os.Getenv("API_USER"), // Replace with your username
|
|
APIKey: os.Getenv("API_KEY"), // Replace with your API key
|
|
}
|
|
|
|
// Log: Getting a single user.
|
|
log.Println("Getting a single user: ")
|
|
|
|
// Specify the username for retrieval.
|
|
username := "selloo" // Replace with the desired username.
|
|
|
|
// Call the GetUser function to retrieve the specified user.
|
|
user, err := endpoints.GetUser(requestContext, username)
|
|
|
|
if err != nil {
|
|
log.Println(err)
|
|
} else {
|
|
// Log the ID of the retrieved user.
|
|
log.Println(user.ID)
|
|
}
|
|
log.Println("----------")
|
|
|
|
// Log: Getting a list of users.
|
|
log.Println("Getting a list of users: ")
|
|
|
|
// Define query parameters for retrieving a list of users.
|
|
query := map[string]string{
|
|
"limit": "5",
|
|
}
|
|
|
|
// Call the GetUsers function to retrieve a list of users based on the query parameters.
|
|
userList, err := endpoints.GetUsers(requestContext, query)
|
|
|
|
if err != nil {
|
|
log.Println(err)
|
|
} else {
|
|
// Log the number of users retrieved.
|
|
log.Println(len(userList))
|
|
}
|
|
log.Println("----------")
|
|
}
|