This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/example/lowlevel/user.go

56 lines
1.4 KiB
Go
Raw Normal View History

2023-10-16 13:56:00 +00:00
package main
import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
"log"
"net/http"
)
func main() {
// Define the request context with essential information.
2023-10-16 13:56:00 +00:00
requestContext := model.RequestContext{
Client: http.Client{},
2023-10-16 13:56:00 +00:00
Host: "https://e621.net",
UserAgent: "Go-e621-SDK (@username)",
Username: "", // Replace with your username
APIKey: "", // Replace with your API key
2023-10-16 13:56:00 +00:00
}
// 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)
2023-10-16 13:56:00 +00:00
if err != nil {
log.Println(err)
} else {
// Log the ID of the retrieved user.
log.Println(user.ID)
2023-10-16 13:56:00 +00:00
}
log.Println("----------")
// Log: Getting a list of users.
log.Println("Getting a list of users: ")
// Define query parameters for retrieving a list of users.
2023-10-16 13:56:00 +00:00
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)
2023-10-16 13:56:00 +00:00
if err != nil {
log.Println(err)
} else {
// Log the number of users retrieved.
log.Println(len(userList))
2023-10-16 13:56:00 +00:00
}
log.Println("----------")
}