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"
|
2023-10-23 09:24:48 +00:00
|
|
|
_ "github.com/joho/godotenv/autoload"
|
2023-10-16 13:56:00 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2023-10-23 09:24:48 +00:00
|
|
|
"os"
|
2023-10-16 13:56:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-10-19 14:13:38 +00:00
|
|
|
// Define the request context with essential information.
|
2023-10-16 13:56:00 +00:00
|
|
|
requestContext := model.RequestContext{
|
2023-10-23 08:21:25 +00:00
|
|
|
Client: http.Client{},
|
2023-10-16 13:56:00 +00:00
|
|
|
Host: "https://e621.net",
|
|
|
|
UserAgent: "Go-e621-SDK (@username)",
|
2023-10-23 09:24:48 +00:00
|
|
|
Username: os.Getenv("API_USER"), // Replace with your username
|
|
|
|
APIKey: os.Getenv("API_KEY"), // Replace with your API key
|
2023-10-16 13:56:00 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 14:13:38 +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.
|
2023-10-23 08:21:25 +00:00
|
|
|
user, err := endpoints.GetUser(requestContext, username)
|
2023-10-19 14:13:38 +00:00
|
|
|
|
2023-10-16 13:56:00 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
2023-10-19 14:13:38 +00:00
|
|
|
} else {
|
|
|
|
// Log the ID of the retrieved user.
|
|
|
|
log.Println(user.ID)
|
2023-10-16 13:56:00 +00:00
|
|
|
}
|
|
|
|
log.Println("----------")
|
|
|
|
|
2023-10-19 14:13:38 +00:00
|
|
|
// 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",
|
|
|
|
}
|
|
|
|
|
2023-10-19 14:13:38 +00:00
|
|
|
// Call the GetUsers function to retrieve a list of users based on the query parameters.
|
2023-10-23 08:21:25 +00:00
|
|
|
userList, err := endpoints.GetUsers(requestContext, query)
|
2023-10-19 14:13:38 +00:00
|
|
|
|
2023-10-16 13:56:00 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
2023-10-19 14:13:38 +00:00
|
|
|
} else {
|
|
|
|
// Log the number of users retrieved.
|
|
|
|
log.Println(len(userList))
|
2023-10-16 13:56:00 +00:00
|
|
|
}
|
|
|
|
log.Println("----------")
|
|
|
|
}
|