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/midlevel/user.go

55 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/builder"
"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.
userBuilder := builder.NewGetUserBuilder(requestContext)
user, err := userBuilder.SetUsername(username).Execute()
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: ")
// Call the GetUsers function to retrieve a list of users based on the query parameters.
usersBuilder := builder.NewGetUsersBuilder(requestContext)
userList, err := usersBuilder.SetLimit(5).Execute()
if err != nil {
log.Println(err)
} else {
// Log the number of users retrieved.
log.Println(len(userList))
}
log.Println("----------")
}