2023-10-19 13:30:36 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-24 13:10:39 +00:00
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
2023-10-23 09:24:48 +00:00
|
|
|
_ "github.com/joho/godotenv/autoload"
|
2023-10-19 13:30:36 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2023-10-23 09:24:48 +00:00
|
|
|
"os"
|
2023-10-19 13:30:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-10-19 14:13:38 +00:00
|
|
|
// Define the request context with essential information.
|
2023-10-19 13:30:36 +00:00
|
|
|
requestContext := model.RequestContext{
|
2023-10-23 09:24:48 +00:00
|
|
|
Client: http.Client{},
|
2023-10-19 13:30:36 +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-19 13:30:36 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 14:13:38 +00:00
|
|
|
// Log: Getting a single note.
|
2023-10-19 13:30:36 +00:00
|
|
|
log.Println("Getting single note: ")
|
2023-10-19 14:13:38 +00:00
|
|
|
|
|
|
|
// Specify the note ID for retrieval.
|
|
|
|
noteID := "36957" // Replace with the desired note's ID.
|
|
|
|
|
|
|
|
// Call the GetNote function to retrieve the specified note.
|
2023-10-23 13:35:14 +00:00
|
|
|
note, err := endpoints.GetNote(requestContext, noteID)
|
2023-10-19 13:30:36 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
2023-10-19 14:13:38 +00:00
|
|
|
} else {
|
|
|
|
// Log the body of the retrieved note.
|
|
|
|
log.Println(note.Body)
|
2023-10-19 13:30:36 +00:00
|
|
|
}
|
|
|
|
log.Println("----------")
|
|
|
|
|
2023-10-19 14:13:38 +00:00
|
|
|
// Log: Getting a list of notes.
|
|
|
|
log.Println("Getting a list of notes: ")
|
|
|
|
|
|
|
|
// Define query parameters for retrieving a list of notes.
|
2023-10-19 13:30:36 +00:00
|
|
|
query := map[string]string{
|
|
|
|
"limit": "5",
|
|
|
|
}
|
2023-10-19 14:13:38 +00:00
|
|
|
|
|
|
|
// Call the GetNotes function to retrieve a list of notes based on the query parameters.
|
2023-10-23 13:35:14 +00:00
|
|
|
notes, err := endpoints.GetNotes(requestContext, query)
|
2023-10-19 13:30:36 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
2023-10-19 14:13:38 +00:00
|
|
|
} else {
|
|
|
|
// Log the number of notes retrieved.
|
|
|
|
log.Println(len(notes))
|
2023-10-19 13:30:36 +00:00
|
|
|
}
|
|
|
|
log.Println("----------")
|
|
|
|
}
|