docs: added basic documentation (needs further reviewer)

Signed-off-by: SoXX <soxx@fenpa.ws>
This commit is contained in:
SoXX 2023-11-06 15:56:36 +01:00
parent 12b8bb5b2c
commit 9173ee8279
14 changed files with 233 additions and 80 deletions

View File

@ -7,13 +7,19 @@ import (
"strconv" "strconv"
) )
// FavoritesBuilder represents a builder for constructing queries to retrieve user's favorite posts.
type FavoritesBuilder interface { type FavoritesBuilder interface {
// SetUserID sets the user ID for the query.
SetUserID(userID model.UserID) FavoritesBuilder SetUserID(userID model.UserID) FavoritesBuilder
// SetLimit sets the maximum number of favorite posts to retrieve.
SetLimit(limitFavorites int) FavoritesBuilder SetLimit(limitFavorites int) FavoritesBuilder
Page(number int) FavoritesBuilder // Page sets the page number for paginated results.
Page(pageNumber int) FavoritesBuilder
// Execute sends the constructed query and returns a slice of favorite posts and an error if any.
Execute() ([]model.Post, error) Execute() ([]model.Post, error)
} }
// NewGetFavoritesBuilder creates a new FavoritesBuilder with the provided RequestContext.
func NewGetFavoritesBuilder(requestContext model.RequestContext) FavoritesBuilder { func NewGetFavoritesBuilder(requestContext model.RequestContext) FavoritesBuilder {
return &getFavorites{ return &getFavorites{
requestContext: requestContext, requestContext: requestContext,
@ -26,21 +32,25 @@ type getFavorites struct {
requestContext model.RequestContext requestContext model.RequestContext
} }
// SetUserID sets the user ID for the query.
func (g *getFavorites) SetUserID(userID model.UserID) FavoritesBuilder { func (g *getFavorites) SetUserID(userID model.UserID) FavoritesBuilder {
g.query["user_id"] = strconv.Itoa(int(userID)) g.query["user_id"] = strconv.Itoa(int(userID))
return g return g
} }
// SetLimit sets the maximum number of favorite posts to retrieve.
func (g *getFavorites) SetLimit(limitFavorites int) FavoritesBuilder { func (g *getFavorites) SetLimit(limitFavorites int) FavoritesBuilder {
g.query["limit"] = strconv.Itoa(limitFavorites) g.query["limit"] = strconv.Itoa(limitFavorites)
return g return g
} }
// Page sets the page number for paginated results.
func (g *getFavorites) Page(pageNumber int) FavoritesBuilder { func (g *getFavorites) Page(pageNumber int) FavoritesBuilder {
g.query["page"] = strconv.Itoa(pageNumber) g.query["page"] = strconv.Itoa(pageNumber)
return g return g
} }
// Execute sends the constructed query and returns a slice of favorite posts and an error if any.
func (g *getFavorites) Execute() ([]model.Post, error) { func (g *getFavorites) Execute() ([]model.Post, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -50,7 +60,6 @@ func (g *getFavorites) Execute() ([]model.Post, error) {
} }
favorites, err := endpoints.GetFavorites(g.requestContext, g.query) favorites, err := endpoints.GetFavorites(g.requestContext, g.query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return favorites, nil return favorites, nil

View File

@ -7,14 +7,17 @@ import (
"strconv" "strconv"
) )
// NoteBuilder represents a builder for constructing queries to retrieve a specific note.
type NoteBuilder interface { type NoteBuilder interface {
// SetNoteID sets the note ID for the query.
SetNoteID(noteID int) NoteBuilder SetNoteID(noteID int) NoteBuilder
// Execute sends the constructed query and returns the requested note and an error, if any.
Execute() (*model.Note, error) Execute() (*model.Note, error)
} }
// NewGetNoteBuilder creates a new NoteBuilder with the provided RequestContext.
func NewGetNoteBuilder(requestContext model.RequestContext) NoteBuilder { func NewGetNoteBuilder(requestContext model.RequestContext) NoteBuilder {
return &getNote{requestContext: requestContext} return &getNote{requestContext: requestContext}
} }
type getNote struct { type getNote struct {
@ -22,11 +25,13 @@ type getNote struct {
noteID int noteID int
} }
// SetNoteID sets the note ID for the query.
func (g *getNote) SetNoteID(noteID int) NoteBuilder { func (g *getNote) SetNoteID(noteID int) NoteBuilder {
g.noteID = noteID g.noteID = noteID
return g return g
} }
// Execute sends the constructed query and returns the requested note and an error, if any.
func (g *getNote) Execute() (*model.Note, error) { func (g *getNote) Execute() (*model.Note, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -36,9 +41,7 @@ func (g *getNote) Execute() (*model.Note, error) {
} }
note, err := endpoints.GetNote(g.requestContext, strconv.Itoa(g.noteID)) note, err := endpoints.GetNote(g.requestContext, strconv.Itoa(g.noteID))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &note, nil return &note, nil
} }

View File

@ -7,17 +7,27 @@ import (
"strconv" "strconv"
) )
// NotesBuilder represents a builder for constructing queries to retrieve notes.
type NotesBuilder interface { type NotesBuilder interface {
// SearchInBody sets the query to search for notes containing a specific text in their body.
SearchInBody(body string) NotesBuilder SearchInBody(body string) NotesBuilder
// NoteID sets the query to search for a note with a specific note ID.
NoteID(noteID int) NotesBuilder NoteID(noteID int) NotesBuilder
// SearchTags sets the query to search for notes containing specific tags.
SearchTags(tags string) NotesBuilder SearchTags(tags string) NotesBuilder
// SearchCreatorID sets the query to search for notes created by a specific user (by their user ID).
SearchCreatorID(creatorID int) NotesBuilder SearchCreatorID(creatorID int) NotesBuilder
searchCreatorName(creatorName string) NotesBuilder // SearchCreatorName sets the query to search for notes created by a specific user (by their username).
SearchCreatorName(creatorName string) NotesBuilder
// Active sets whether to search for active or inactive notes.
Active(isActive bool) NotesBuilder Active(isActive bool) NotesBuilder
// SetLimit sets the maximum number of notes to retrieve.
SetLimit(limitNotes int) NotesBuilder SetLimit(limitNotes int) NotesBuilder
// Execute sends the constructed query and returns a slice of notes and an error, if any.
Execute() ([]model.Note, error) Execute() ([]model.Note, error)
} }
// NewGetNotesBuilder creates a new NotesBuilder with the provided RequestContext.
func NewGetNotesBuilder(requestContext model.RequestContext) NotesBuilder { func NewGetNotesBuilder(requestContext model.RequestContext) NotesBuilder {
return &getNotes{ return &getNotes{
requestContext: requestContext, requestContext: requestContext,
@ -30,42 +40,50 @@ type getNotes struct {
query map[string]string query map[string]string
} }
func (g getNotes) SearchInBody(body string) NotesBuilder { // SearchInBody sets the query to search for notes containing a specific text in their body.
func (g *getNotes) SearchInBody(body string) NotesBuilder {
g.query["search[body_matches]"] = body g.query["search[body_matches]"] = body
return g return g
} }
func (g getNotes) NoteID(noteID int) NotesBuilder { // NoteID sets the query to search for a note with a specific note ID.
func (g *getNotes) NoteID(noteID int) NotesBuilder {
g.query["search[post_id]"] = strconv.Itoa(noteID) g.query["search[post_id]"] = strconv.Itoa(noteID)
return g return g
} }
func (g getNotes) SearchTags(tags string) NotesBuilder { // SearchTags sets the query to search for notes containing specific tags.
func (g *getNotes) SearchTags(tags string) NotesBuilder {
g.query["search[post_tags_match]"] = tags g.query["search[post_tags_match]"] = tags
return g return g
} }
func (g getNotes) SearchCreatorID(creatorID int) NotesBuilder { // SearchCreatorID sets the query to search for notes created by a specific user (by their user ID).
func (g *getNotes) SearchCreatorID(creatorID int) NotesBuilder {
g.query["search[creator_id]"] = strconv.Itoa(creatorID) g.query["search[creator_id]"] = strconv.Itoa(creatorID)
return g return g
} }
func (g getNotes) searchCreatorName(creatorName string) NotesBuilder { // SearchCreatorName sets the query to search for notes created by a specific user (by their username).
func (g *getNotes) SearchCreatorName(creatorName string) NotesBuilder {
g.query["search[creator_name]"] = creatorName g.query["search[creator_name]"] = creatorName
return g return g
} }
func (g getNotes) Active(isActive bool) NotesBuilder { // Active sets whether to search for active or inactive notes.
func (g *getNotes) Active(isActive bool) NotesBuilder {
g.query["search[is_active]"] = strconv.FormatBool(isActive) g.query["search[is_active]"] = strconv.FormatBool(isActive)
return g return g
} }
func (g getNotes) SetLimit(limitNotes int) NotesBuilder { // SetLimit sets the maximum number of notes to retrieve.
func (g *getNotes) SetLimit(limitNotes int) NotesBuilder {
g.query["limit"] = strconv.Itoa(limitNotes) g.query["limit"] = strconv.Itoa(limitNotes)
return g return g
} }
func (g getNotes) Execute() ([]model.Note, error) { // Execute sends the constructed query and returns a slice of notes and an error, if any.
func (g *getNotes) Execute() ([]model.Note, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil { if err != nil {
@ -74,7 +92,6 @@ func (g getNotes) Execute() ([]model.Note, error) {
} }
notes, err := endpoints.GetNotes(g.requestContext, g.query) notes, err := endpoints.GetNotes(g.requestContext, g.query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return notes, nil return notes, nil

View File

@ -7,11 +7,15 @@ import (
"strconv" "strconv"
) )
// PoolBuilder represents a builder for constructing queries to retrieve a specific pool.
type PoolBuilder interface { type PoolBuilder interface {
// ID sets the pool ID for the query.
ID(poolID int) PoolBuilder ID(poolID int) PoolBuilder
// Execute sends the constructed query and returns the requested pool and an error, if any.
Execute() (model.Pool, error) Execute() (model.Pool, error)
} }
// NewGetPoolBuilder creates a new PoolBuilder with the provided RequestContext.
func NewGetPoolBuilder(requestContext model.RequestContext) PoolBuilder { func NewGetPoolBuilder(requestContext model.RequestContext) PoolBuilder {
return &getPool{requestContext: requestContext} return &getPool{requestContext: requestContext}
} }
@ -21,12 +25,14 @@ type getPool struct {
id int id int
} }
func (g getPool) ID(poolID int) PoolBuilder { // ID sets the pool ID for the query.
func (g *getPool) ID(poolID int) PoolBuilder {
g.id = poolID g.id = poolID
return g return g
} }
func (g getPool) Execute() (model.Pool, error) { // Execute sends the constructed query and returns the requested pool and an error, if any.
func (g *getPool) Execute() (model.Pool, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil { if err != nil {
@ -35,7 +41,6 @@ func (g getPool) Execute() (model.Pool, error) {
} }
pool, err := endpoints.GetPool(g.requestContext, strconv.Itoa(g.id)) pool, err := endpoints.GetPool(g.requestContext, strconv.Itoa(g.id))
if err != nil { if err != nil {
return model.Pool{}, err return model.Pool{}, err
} }
return pool, nil return pool, nil

View File

@ -7,22 +7,34 @@ import (
"strconv" "strconv"
) )
// PoolsBuilder represents a builder for constructing queries to retrieve pools.
type PoolsBuilder interface { type PoolsBuilder interface {
// SearchName sets the query to search for pools with a specific name.
SearchName(name string) PoolsBuilder SearchName(name string) PoolsBuilder
// SearchID sets the query to search for pools with specific pool IDs.
SearchID(poolIDs string) PoolsBuilder SearchID(poolIDs string) PoolsBuilder
SearchDescritpion(description string) PoolsBuilder // SearchDescription sets the query to search for pools with specific descriptions.
SearchDescription(description string) PoolsBuilder
// SearchCreatorID sets the query to search for pools created by a specific user (by their user ID).
SearchCreatorID(creatorID int) PoolsBuilder SearchCreatorID(creatorID int) PoolsBuilder
searchCreatorName(creatorName string) PoolsBuilder // SearchCreatorName sets the query to search for pools created by a specific user (by their username).
SearchCreatorName(creatorName string) PoolsBuilder
// Active sets whether to search for active or inactive pools.
Active(isActive bool) PoolsBuilder Active(isActive bool) PoolsBuilder
// SearchCategory sets the query to search for pools in a specific category.
SearchCategory(category model.PoolCategory) PoolsBuilder SearchCategory(category model.PoolCategory) PoolsBuilder
// Order sets the ordering of the retrieved pools.
Order(order model.PoolOrder) PoolsBuilder Order(order model.PoolOrder) PoolsBuilder
// SetLimit sets the maximum number of pools to retrieve.
SetLimit(limitPools int) PoolsBuilder SetLimit(limitPools int) PoolsBuilder
// Execute sends the constructed query and returns a slice of pools and an error, if any.
Execute() ([]model.Pool, error) Execute() ([]model.Pool, error)
} }
func NewGetPoolsBuilder(requstContext model.RequestContext) PoolsBuilder { // NewGetPoolsBuilder creates a new PoolsBuilder with the provided RequestContext.
func NewGetPoolsBuilder(requestContext model.RequestContext) PoolsBuilder {
return &getPools{ return &getPools{
requestContext: requstContext, requestContext: requestContext,
query: make(map[string]string), query: make(map[string]string),
} }
} }
@ -32,51 +44,61 @@ type getPools struct {
query map[string]string query map[string]string
} }
// SearchName sets the query to search for pools with a specific name.
func (g *getPools) SearchName(name string) PoolsBuilder { func (g *getPools) SearchName(name string) PoolsBuilder {
g.query["search[name_matches]"] = name g.query["search[name_matches]"] = name
return g return g
} }
// SearchID sets the query to search for pools with specific pool IDs.
func (g *getPools) SearchID(poolIDs string) PoolsBuilder { func (g *getPools) SearchID(poolIDs string) PoolsBuilder {
g.query["search[id]"] = poolIDs g.query["search[id]"] = poolIDs
return g return g
} }
func (g *getPools) SearchDescritpion(description string) PoolsBuilder { // SearchDescription sets the query to search for pools with specific descriptions.
func (g *getPools) SearchDescription(description string) PoolsBuilder {
g.query["search[description_matches]"] = description g.query["search[description_matches]"] = description
return g return g
} }
// SearchCreatorID sets the query to search for pools created by a specific user (by their user ID).
func (g *getPools) SearchCreatorID(creatorID int) PoolsBuilder { func (g *getPools) SearchCreatorID(creatorID int) PoolsBuilder {
g.query["search[creator_id]"] = strconv.Itoa(creatorID) g.query["search[creator_id]"] = strconv.Itoa(creatorID)
return g return g
} }
func (g *getPools) searchCreatorName(creatorName string) PoolsBuilder { // SearchCreatorName sets the query to search for pools created by a specific user (by their username).
func (g *getPools) SearchCreatorName(creatorName string) PoolsBuilder {
g.query["search[creator_name]"] = creatorName g.query["search[creator_name]"] = creatorName
return g return g
} }
// Active sets whether to search for active or inactive pools.
func (g *getPools) Active(isActive bool) PoolsBuilder { func (g *getPools) Active(isActive bool) PoolsBuilder {
g.query["search[is_active]"] = strconv.FormatBool(isActive) g.query["search[is_active]"] = strconv.FormatBool(isActive)
return g return g
} }
// SearchCategory sets the query to search for pools in a specific category.
func (g *getPools) SearchCategory(category model.PoolCategory) PoolsBuilder { func (g *getPools) SearchCategory(category model.PoolCategory) PoolsBuilder {
g.query["search[category]"] = string(category) g.query["search[category]"] = string(category)
return g return g
} }
// Order sets the ordering of the retrieved pools.
func (g *getPools) Order(order model.PoolOrder) PoolsBuilder { func (g *getPools) Order(order model.PoolOrder) PoolsBuilder {
g.query["search[order]"] = string(order) g.query["search[order]"] = string(order)
return g return g
} }
func (g *getPools) SetLimit(limitUser int) PoolsBuilder { // SetLimit sets the maximum number of pools to retrieve.
g.query["limit"] = strconv.Itoa(limitUser) func (g *getPools) SetLimit(limitPools int) PoolsBuilder {
g.query["limit"] = strconv.Itoa(limitPools)
return g return g
} }
// Execute sends the constructed query and returns a slice of pools and an error, if any.
func (g *getPools) Execute() ([]model.Pool, error) { func (g *getPools) Execute() ([]model.Pool, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -86,7 +108,6 @@ func (g *getPools) Execute() ([]model.Pool, error) {
} }
pools, err := endpoints.GetPools(g.requestContext, g.query) pools, err := endpoints.GetPools(g.requestContext, g.query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return pools, nil return pools, nil

View File

@ -7,11 +7,15 @@ import (
"strconv" "strconv"
) )
// PostBuilder represents a builder for constructing queries to retrieve a specific post.
type PostBuilder interface { type PostBuilder interface {
// SetPostID sets the post ID for the query.
SetPostID(postID model.PostID) PostBuilder SetPostID(postID model.PostID) PostBuilder
// Execute sends the constructed query and returns the requested post and an error, if any.
Execute() (*model.Post, error) Execute() (*model.Post, error)
} }
// NewGetPostBuilder creates a new PostBuilder with the provided RequestContext.
func NewGetPostBuilder(requestContext model.RequestContext) PostBuilder { func NewGetPostBuilder(requestContext model.RequestContext) PostBuilder {
return &getPost{requestContext: requestContext} return &getPost{requestContext: requestContext}
} }
@ -21,11 +25,13 @@ type getPost struct {
postID model.PostID postID model.PostID
} }
// SetPostID sets the post ID for the query.
func (g *getPost) SetPostID(postID model.PostID) PostBuilder { func (g *getPost) SetPostID(postID model.PostID) PostBuilder {
g.postID = postID g.postID = postID
return g return g
} }
// Execute sends the constructed query and returns the requested post and an error, if any.
func (g *getPost) Execute() (*model.Post, error) { func (g *getPost) Execute() (*model.Post, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -35,7 +41,6 @@ func (g *getPost) Execute() (*model.Post, error) {
} }
post, err := endpoints.GetPost(g.requestContext, strconv.Itoa(int(g.postID))) post, err := endpoints.GetPost(g.requestContext, strconv.Itoa(int(g.postID)))
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &post, nil return &post, nil

View File

@ -8,17 +8,25 @@ import (
"strconv" "strconv"
) )
// PostsBuilder represents a builder for constructing queries to retrieve posts.
type PostsBuilder interface { type PostsBuilder interface {
// Tags sets the query to search for posts with specific tags.
Tags(tags string) PostsBuilder Tags(tags string) PostsBuilder
// PageAfter sets the query to retrieve posts after a specific post ID.
PageAfter(postID model.PostID) PostsBuilder PageAfter(postID model.PostID) PostsBuilder
// PageBefore sets the query to retrieve posts before a specific post ID.
PageBefore(postID model.PostID) PostsBuilder PageBefore(postID model.PostID) PostsBuilder
// PageNumber sets the query to retrieve posts on a specific page number.
PageNumber(number int) PostsBuilder PageNumber(number int) PostsBuilder
// SetLimit sets the maximum number of posts to retrieve.
SetLimit(limitUser int) PostsBuilder SetLimit(limitUser int) PostsBuilder
// Execute sends the constructed query and returns a slice of posts and an error, if any.
Execute() ([]model.Post, error) Execute() ([]model.Post, error)
} }
// NewGetPostsBuilder creates a new PostsBuilder with the provided RequestContext.
func NewGetPostsBuilder(requestContext model.RequestContext) PostsBuilder { func NewGetPostsBuilder(requestContext model.RequestContext) PostsBuilder {
var postBuilder PostsBuilder = &getPosts{ postBuilder := &getPosts{
requestContext: requestContext, requestContext: requestContext,
query: make(map[string]string), query: make(map[string]string),
} }
@ -31,31 +39,37 @@ type getPosts struct {
query map[string]string query map[string]string
} }
// Tags sets the query to search for posts with specific tags.
func (g *getPosts) Tags(tags string) PostsBuilder { func (g *getPosts) Tags(tags string) PostsBuilder {
g.query["tags"] = tags g.query["tags"] = tags
return g return g
} }
// PageAfter sets the query to retrieve posts after a specific post ID.
func (g *getPosts) PageAfter(postID model.PostID) PostsBuilder { func (g *getPosts) PageAfter(postID model.PostID) PostsBuilder {
g.query["page"] = "a" + strconv.Itoa(int(postID)) g.query["page"] = "a" + strconv.Itoa(int(postID))
return g return g
} }
// PageBefore sets the query to retrieve posts before a specific post ID.
func (g *getPosts) PageBefore(postID model.PostID) PostsBuilder { func (g *getPosts) PageBefore(postID model.PostID) PostsBuilder {
g.query["page"] = "b" + strconv.Itoa(int(postID)) g.query["page"] = "b" + strconv.Itoa(int(postID))
return g return g
} }
// PageNumber sets the query to retrieve posts on a specific page number.
func (g *getPosts) PageNumber(number int) PostsBuilder { func (g *getPosts) PageNumber(number int) PostsBuilder {
g.query["page"] = strconv.Itoa(number) g.query["page"] = strconv.Itoa(number)
return g return g
} }
// SetLimit sets the maximum number of posts to retrieve.
func (g *getPosts) SetLimit(limitUser int) PostsBuilder { func (g *getPosts) SetLimit(limitUser int) PostsBuilder {
g.query["limit"] = strconv.Itoa(limitUser) g.query["limit"] = strconv.Itoa(limitUser)
return g return g
} }
// Execute sends the constructed query and returns a slice of posts and an error, if any.
func (g *getPosts) Execute() ([]model.Post, error) { func (g *getPosts) Execute() ([]model.Post, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -65,7 +79,6 @@ func (g *getPosts) Execute() ([]model.Post, error) {
} }
posts, err := endpoints.GetPosts(g.requestContext, g.query) posts, err := endpoints.GetPosts(g.requestContext, g.query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return posts, err return posts, err

View File

@ -7,13 +7,17 @@ import (
"strconv" "strconv"
) )
// TagBuilder represents a builder for constructing queries to retrieve a specific tag.
type TagBuilder interface { type TagBuilder interface {
// SetTagID sets the tag ID for the query.
SetTagID(tagID int) TagBuilder SetTagID(tagID int) TagBuilder
// Execute sends the constructed query and returns the requested tag and an error, if any.
Execute() (model.Tag, error) Execute() (model.Tag, error)
} }
func NewGetTagBuilder(requstContext model.RequestContext) TagBuilder { // NewGetTagBuilder creates a new TagBuilder with the provided RequestContext.
return &getTag{requestContext: requstContext} func NewGetTagBuilder(requestContext model.RequestContext) TagBuilder {
return &getTag{requestContext: requestContext}
} }
type getTag struct { type getTag struct {
@ -21,11 +25,13 @@ type getTag struct {
tagID int tagID int
} }
// SetTagID sets the tag ID for the query.
func (g *getTag) SetTagID(tagID int) TagBuilder { func (g *getTag) SetTagID(tagID int) TagBuilder {
g.tagID = tagID g.tagID = tagID
return g return g
} }
// Execute sends the constructed query and returns the requested tag and an error, if any.
func (g *getTag) Execute() (model.Tag, error) { func (g *getTag) Execute() (model.Tag, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -35,7 +41,6 @@ func (g *getTag) Execute() (model.Tag, error) {
} }
tag, err := endpoints.GetTag(g.requestContext, strconv.Itoa(g.tagID)) tag, err := endpoints.GetTag(g.requestContext, strconv.Itoa(g.tagID))
if err != nil { if err != nil {
return model.Tag{}, err return model.Tag{}, err
} }
return tag, nil return tag, nil

View File

@ -7,20 +7,31 @@ import (
"strconv" "strconv"
) )
// TagsBuilder represents a builder for constructing queries to retrieve tags.
type TagsBuilder interface { type TagsBuilder interface {
// SearchName sets the query to search for tags with specific names.
SearchName(name string) TagsBuilder SearchName(name string) TagsBuilder
// SearchCategory sets the query to search for tags in a specific category.
SearchCategory(category model.TagCategory) TagsBuilder SearchCategory(category model.TagCategory) TagsBuilder
// Order sets the query to order tags by a specific criterion.
Order(order string) TagsBuilder Order(order string) TagsBuilder
// HideEmpty sets the query to filter out tags that are empty.
HideEmpty(hideEmpty bool) TagsBuilder HideEmpty(hideEmpty bool) TagsBuilder
// Wiki sets the query to filter tags that have a wiki.
Wiki(hasWiki bool) TagsBuilder Wiki(hasWiki bool) TagsBuilder
// Artist sets the query to filter tags that have an artist page.
Artist(hasArtistPage bool) TagsBuilder Artist(hasArtistPage bool) TagsBuilder
// SetPage sets the query to retrieve tags from a specific page number.
SetPage(pageNumber int) TagsBuilder SetPage(pageNumber int) TagsBuilder
// SetLimit sets the maximum number of tags to retrieve.
SetLimit(limitUser int) TagsBuilder SetLimit(limitUser int) TagsBuilder
// Execute sends the constructed query and returns a slice of tags and an error, if any.
Execute() ([]model.Tag, error) Execute() ([]model.Tag, error)
} }
func NewGetTagsBuilder(requstContext model.RequestContext) TagsBuilder { // NewGetTagsBuilder creates a new TagsBuilder with the provided RequestContext.
return &getTags{requestContext: requstContext, query: make(map[string]string)} func NewGetTagsBuilder(requestContext model.RequestContext) TagsBuilder {
return &getTags{requestContext: requestContext, query: make(map[string]string)}
} }
type getTags struct { type getTags struct {
@ -28,46 +39,55 @@ type getTags struct {
query map[string]string query map[string]string
} }
// SearchName sets the query to search for tags with specific names.
func (g *getTags) SearchName(name string) TagsBuilder { func (g *getTags) SearchName(name string) TagsBuilder {
g.query["search[name_matches]"] = name g.query["search[name_matches]"] = name
return g return g
} }
// SearchCategory sets the query to search for tags in a specific category.
func (g *getTags) SearchCategory(category model.TagCategory) TagsBuilder { func (g *getTags) SearchCategory(category model.TagCategory) TagsBuilder {
g.query["search[category]"] = strconv.Itoa(int(category)) g.query["search[category]"] = strconv.Itoa(int(category))
return g return g
} }
// Order sets the query to order tags by a specific criterion.
func (g *getTags) Order(order string) TagsBuilder { func (g *getTags) Order(order string) TagsBuilder {
g.query["search[order]"] = order g.query["search[order]"] = order
return g return g
} }
// HideEmpty sets the query to filter out tags that are empty.
func (g *getTags) HideEmpty(hideEmpty bool) TagsBuilder { func (g *getTags) HideEmpty(hideEmpty bool) TagsBuilder {
g.query["search[hide_empty]"] = strconv.FormatBool(hideEmpty) g.query["search[hide_empty]"] = strconv.FormatBool(hideEmpty)
return g return g
} }
// Wiki sets the query to filter tags that have a wiki.
func (g *getTags) Wiki(hasWiki bool) TagsBuilder { func (g *getTags) Wiki(hasWiki bool) TagsBuilder {
g.query["search[has_wiki]"] = strconv.FormatBool(hasWiki) g.query["search[has_wiki]"] = strconv.FormatBool(hasWiki)
return g return g
} }
// Artist sets the query to filter tags that have an artist page.
func (g *getTags) Artist(hasArtistPage bool) TagsBuilder { func (g *getTags) Artist(hasArtistPage bool) TagsBuilder {
g.query["search[has_artist]"] = strconv.FormatBool(hasArtistPage) g.query["search[has_artist]"] = strconv.FormatBool(hasArtistPage)
return g return g
} }
// SetPage sets the query to retrieve tags from a specific page number.
func (g *getTags) SetPage(pageNumber int) TagsBuilder { func (g *getTags) SetPage(pageNumber int) TagsBuilder {
g.query["page"] = strconv.Itoa(pageNumber) g.query["page"] = strconv.Itoa(pageNumber)
return g return g
} }
// SetLimit sets the maximum number of tags to retrieve.
func (g *getTags) SetLimit(limitUser int) TagsBuilder { func (g *getTags) SetLimit(limitUser int) TagsBuilder {
g.query["limit"] = strconv.Itoa(limitUser) g.query["limit"] = strconv.Itoa(limitUser)
return g return g
} }
// Execute sends the constructed query and returns a slice of tags and an error, if any.
func (g *getTags) Execute() ([]model.Tag, error) { func (g *getTags) Execute() ([]model.Tag, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -77,7 +97,6 @@ func (g *getTags) Execute() ([]model.Tag, error) {
} }
tags, err := endpoints.GetTags(g.requestContext, g.query) tags, err := endpoints.GetTags(g.requestContext, g.query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return tags, err return tags, err

View File

@ -6,11 +6,15 @@ import (
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model" "git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
) )
// UserBuilder represents a builder for constructing queries to retrieve user information.
type UserBuilder interface { type UserBuilder interface {
// SetUsername sets the username for the query to retrieve user information.
SetUsername(username string) UserBuilder SetUsername(username string) UserBuilder
// Execute sends the constructed query and returns the requested user information and an error, if any.
Execute() (model.User, error) Execute() (model.User, error)
} }
// NewGetUserBuilder creates a new UserBuilder with the provided RequestContext.
func NewGetUserBuilder(requestContext model.RequestContext) UserBuilder { func NewGetUserBuilder(requestContext model.RequestContext) UserBuilder {
return &getUser{requestContext: requestContext} return &getUser{requestContext: requestContext}
} }
@ -20,11 +24,13 @@ type getUser struct {
username string username string
} }
// SetUsername sets the username for the query to retrieve user information.
func (g *getUser) SetUsername(username string) UserBuilder { func (g *getUser) SetUsername(username string) UserBuilder {
g.username = username g.username = username
return g return g
} }
// Execute sends the constructed query and returns the requested user information and an error, if any.
func (g *getUser) Execute() (model.User, error) { func (g *getUser) Execute() (model.User, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -34,7 +40,6 @@ func (g *getUser) Execute() (model.User, error) {
} }
user, err := endpoints.GetUser(g.requestContext, g.username) user, err := endpoints.GetUser(g.requestContext, g.username)
if err != nil { if err != nil {
return model.User{}, err return model.User{}, err
} }
return user, nil return user, nil

View File

@ -7,21 +7,35 @@ import (
"strconv" "strconv"
) )
// UsersBuilder represents a builder for constructing queries to retrieve user information.
type UsersBuilder interface { type UsersBuilder interface {
// SetPage sets the page number for paginated results.
SetPage(pageNumber int) UsersBuilder SetPage(pageNumber int) UsersBuilder
// SetLimit sets the maximum number of users to retrieve.
SetLimit(limitUser int) UsersBuilder SetLimit(limitUser int) UsersBuilder
// SearchByName specifies a username to search for.
SearchByName(userName string) UsersBuilder SearchByName(userName string) UsersBuilder
// SearchByAbout specifies a text to search in the 'about' field of user profiles.
SearchByAbout(about string) UsersBuilder SearchByAbout(about string) UsersBuilder
SearchByAvatarID(postID model.PostID) UsersBuilder // SearchByAvatarID specifies an avatar ID to search for.
SearchByAvatarID(avatarID model.PostID) UsersBuilder
// SearchByLevel specifies a user level to filter by.
SearchByLevel(level model.UserLevel) UsersBuilder SearchByLevel(level model.UserLevel) UsersBuilder
SearchByMinLevel(level model.UserLevel) UsersBuilder // SearchByMinLevel specifies the minimum user level to filter by.
SearchByMaxLevellevel(model.UserLevel) UsersBuilder SearchByMinLevel(minLevel model.UserLevel) UsersBuilder
searchByCanUpload(canUpload bool) UsersBuilder // SearchByMaxLevel specifies the maximum user level to filter by.
SearchByMaxLevel(maxLevel model.UserLevel) UsersBuilder
// SearchByCanUpload specifies whether users can upload free content.
SearchByCanUpload(canUpload bool) UsersBuilder
// SearchByIsApprover specifies whether users can approve posts.
SearchByIsApprover(isApprover bool) UsersBuilder SearchByIsApprover(isApprover bool) UsersBuilder
// SearchByOrder specifies the order in which users are retrieved.
SearchByOrder(order model.Order) UsersBuilder SearchByOrder(order model.Order) UsersBuilder
// Execute sends the constructed query and returns the requested user information and an error, if any.
Execute() ([]model.User, error) Execute() ([]model.User, error)
} }
// NewGetUsersBuilder creates a new UsersBuilder with the provided RequestContext.
func NewGetUsersBuilder(requestContext model.RequestContext) UsersBuilder { func NewGetUsersBuilder(requestContext model.RequestContext) UsersBuilder {
return &getUsers{requestContext: requestContext, query: make(map[string]string)} return &getUsers{requestContext: requestContext, query: make(map[string]string)}
} }
@ -31,61 +45,73 @@ type getUsers struct {
query map[string]string query map[string]string
} }
// SearchByName specifies a username to search for.
func (g *getUsers) SearchByName(userName string) UsersBuilder { func (g *getUsers) SearchByName(userName string) UsersBuilder {
g.query["search[name_matches]"] = userName g.query["search[name_matches]"] = userName
return g return g
} }
// SearchByAbout specifies a text to search in the 'about' field of user profiles.
func (g *getUsers) SearchByAbout(about string) UsersBuilder { func (g *getUsers) SearchByAbout(about string) UsersBuilder {
g.query["search[about_me"] = about g.query["search[about_me]"] = about
return g return g
} }
func (g *getUsers) SearchByAvatarID(postID model.PostID) UsersBuilder { // SearchByAvatarID specifies an avatar ID to search for.
g.query["search[avatar_id]"] = strconv.FormatInt(int64(postID), 10) func (g *getUsers) SearchByAvatarID(avatarID model.PostID) UsersBuilder {
g.query["search[avatar_id]"] = strconv.FormatInt(int64(avatarID), 10)
return g return g
} }
// SearchByLevel specifies a user level to filter by.
func (g *getUsers) SearchByLevel(level model.UserLevel) UsersBuilder { func (g *getUsers) SearchByLevel(level model.UserLevel) UsersBuilder {
g.query["search[level]"] = strconv.Itoa(int(level)) g.query["search[level]"] = strconv.Itoa(int(level))
return g return g
} }
func (g *getUsers) SearchByMinLevel(level model.UserLevel) UsersBuilder { // SearchByMinLevel specifies the minimum user level to filter by.
g.query["search[min_level"] = strconv.Itoa(int(level)) func (g *getUsers) SearchByMinLevel(minLevel model.UserLevel) UsersBuilder {
g.query["search[min_level]"] = strconv.Itoa(int(minLevel))
return g return g
} }
func (g *getUsers) SearchByMaxLevellevel(level model.UserLevel) UsersBuilder { // SearchByMaxLevel specifies the maximum user level to filter by.
g.query["search[max_level]"] = strconv.Itoa(int(level)) func (g *getUsers) SearchByMaxLevel(maxLevel model.UserLevel) UsersBuilder {
g.query["search[max_level]"] = strconv.Itoa(int(maxLevel))
return g return g
} }
func (g *getUsers) searchByCanUpload(canUpload bool) UsersBuilder { // SearchByCanUpload specifies whether users can upload free content.
func (g *getUsers) SearchByCanUpload(canUpload bool) UsersBuilder {
g.query["search[can_upload_free]"] = strconv.FormatBool(canUpload) g.query["search[can_upload_free]"] = strconv.FormatBool(canUpload)
return g return g
} }
// SearchByIsApprover specifies whether users can approve posts.
func (g *getUsers) SearchByIsApprover(isApprover bool) UsersBuilder { func (g *getUsers) SearchByIsApprover(isApprover bool) UsersBuilder {
g.query["search[can_approve_posts]"] = strconv.FormatBool(isApprover) g.query["search[can_approve_posts]"] = strconv.FormatBool(isApprover)
return g return g
} }
// SearchByOrder specifies the order in which users are retrieved.
func (g *getUsers) SearchByOrder(order model.Order) UsersBuilder { func (g *getUsers) SearchByOrder(order model.Order) UsersBuilder {
g.query["search[order]"] = string(order) g.query["search[order]"] = string(order)
return g return g
} }
// SetPage sets the page number for paginated results.
func (g *getUsers) SetPage(pageNumber int) UsersBuilder { func (g *getUsers) SetPage(pageNumber int) UsersBuilder {
g.query["page"] = strconv.Itoa(pageNumber) g.query["page"] = strconv.Itoa(pageNumber)
return g return g
} }
// SetLimit sets the maximum number of users to retrieve.
func (g *getUsers) SetLimit(limitUser int) UsersBuilder { func (g *getUsers) SetLimit(limitUser int) UsersBuilder {
g.query["limit"] = strconv.Itoa(limitUser) g.query["limit"] = strconv.Itoa(limitUser)
return g return g
} }
// Execute sends the constructed query and returns the requested user information and an error, if any.
func (g *getUsers) Execute() ([]model.User, error) { func (g *getUsers) Execute() ([]model.User, error) {
if g.requestContext.RateLimiter != nil { if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background()) err := g.requestContext.RateLimiter.Wait(context.Background())
@ -95,7 +121,6 @@ func (g *getUsers) Execute() ([]model.User, error) {
} }
users, err := endpoints.GetUsers(g.requestContext, g.query) users, err := endpoints.GetUsers(g.requestContext, g.query)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return users, nil return users, nil

View File

@ -12,11 +12,14 @@ import (
"strconv" "strconv"
) )
// Client is the main client for interacting with the e621 API.
type Client struct { type Client struct {
RequestContext model.RequestContext RequestContext model.RequestContext
} }
func NewE621Client(username string, apikey string) Client { // NewE621Client creates a new e621 client with the provided username and API key.
func NewE621Client(username string, apiKey string) Client {
// Create a new e621 client with the given username and API key.
return Client{ return Client{
RequestContext: model.RequestContext{ RequestContext: model.RequestContext{
Client: http.Client{}, Client: http.Client{},
@ -24,30 +27,40 @@ func NewE621Client(username string, apikey string) Client {
Host: "https://e621.net", Host: "https://e621.net",
UserAgent: fmt.Sprintf("Go-e621-SDK used by %s | (made by the Anthrove Team)", username), UserAgent: fmt.Sprintf("Go-e621-SDK used by %s | (made by the Anthrove Team)", username),
Username: username, Username: username,
APIKey: apikey, APIKey: apiKey,
}, },
} }
} }
// SetHost sets the API host for the client.
func (c *Client) SetHost(host string) *Client { func (c *Client) SetHost(host string) *Client {
// Set the API host for the client.
c.RequestContext.Host = host c.RequestContext.Host = host
return c return c
} }
// SetAgentName sets the user agent name for the client.
func (c *Client) SetAgentName(userAgent string) *Client { func (c *Client) SetAgentName(userAgent string) *Client {
// Set the user agent name for the client.
c.RequestContext.UserAgent = userAgent c.RequestContext.UserAgent = userAgent
return c return c
} }
// GetUserByName returns a user builder for a given username.
func (c *Client) GetUserByName(username string) builder.UserBuilder { func (c *Client) GetUserByName(username string) builder.UserBuilder {
// Returns a user builder for the specified username.
return builder.NewGetUserBuilder(c.RequestContext).SetUsername(username) return builder.NewGetUserBuilder(c.RequestContext).SetUsername(username)
} }
// GetUserByID returns a user builder for a given user ID.
func (c *Client) GetUserByID(userID model.UserID) builder.UserBuilder { func (c *Client) GetUserByID(userID model.UserID) builder.UserBuilder {
// Returns a user builder for the specified user ID.
return builder.NewGetUserBuilder(c.RequestContext).SetUsername(strconv.FormatInt(int64(userID), 10)) return builder.NewGetUserBuilder(c.RequestContext).SetUsername(strconv.FormatInt(int64(userID), 10))
} }
// GetFavoritesForUser returns a favorites builder for a given username.
func (c *Client) GetFavoritesForUser(username string) (builder.FavoritesBuilder, error) { func (c *Client) GetFavoritesForUser(username string) (builder.FavoritesBuilder, error) {
// Returns a favorites builder for the specified username.
user, err := builder.NewGetUserBuilder(c.RequestContext).SetUsername(username).Execute() user, err := builder.NewGetUserBuilder(c.RequestContext).SetUsername(username).Execute()
if err != nil { if err != nil {
return nil, err return nil, err
@ -56,7 +69,9 @@ func (c *Client) GetFavoritesForUser(username string) (builder.FavoritesBuilder,
return favoritesBuilder, nil return favoritesBuilder, nil
} }
// GetNFavoritesForUser retrieves a specified number of favorites for a user.
func (c *Client) GetNFavoritesForUser(n int, favoriteBuilder builder.FavoritesBuilder) ([]model.Post, error) { func (c *Client) GetNFavoritesForUser(n int, favoriteBuilder builder.FavoritesBuilder) ([]model.Post, error) {
// Retrieves a specified number of favorite posts for a user.
if n < utils.E621_MAX_POST_COUNT { if n < utils.E621_MAX_POST_COUNT {
favoriteBuilder.SetLimit(n) favoriteBuilder.SetLimit(n)
} }
@ -78,27 +93,36 @@ func (c *Client) GetNFavoritesForUser(n int, favoriteBuilder builder.FavoritesBu
} }
return favorites, nil return favorites, nil
} }
// GetAllFavoritesForUser retrieves all favorites for a user.
func (c *Client) GetAllFavoritesForUser(favoriteBuilder builder.FavoritesBuilder) ([]model.Post, error) { func (c *Client) GetAllFavoritesForUser(favoriteBuilder builder.FavoritesBuilder) ([]model.Post, error) {
// Retrieves all favorite posts for a user.
return c.GetNFavoritesForUser(math.MaxInt, favoriteBuilder) return c.GetNFavoritesForUser(math.MaxInt, favoriteBuilder)
} }
// GetFavoritesForUserWithTags returns a posts builder for a user's favorites with specific tags.
func (c *Client) GetFavoritesForUserWithTags(username string, tags string) builder.PostsBuilder { func (c *Client) GetFavoritesForUserWithTags(username string, tags string) builder.PostsBuilder {
// Returns a posts builder for a user's favorites with specific tags.
favoritesBuilder := builder.NewGetPostsBuilder(c.RequestContext).Tags(fmt.Sprintf("fav:%s %s", username, tags)) favoritesBuilder := builder.NewGetPostsBuilder(c.RequestContext).Tags(fmt.Sprintf("fav:%s %s", username, tags))
return favoritesBuilder return favoritesBuilder
} }
// GetPostByID returns a post builder for a specific post ID.
func (c *Client) GetPostByID(id model.PostID) builder.PostBuilder { func (c *Client) GetPostByID(id model.PostID) builder.PostBuilder {
// Returns a post builder for a specific post ID.
return builder.NewGetPostBuilder(c.RequestContext).SetPostID(id) return builder.NewGetPostBuilder(c.RequestContext).SetPostID(id)
} }
// GetPosts returns a posts builder for general post queries.
func (c *Client) GetPosts() builder.PostsBuilder { func (c *Client) GetPosts() builder.PostsBuilder {
// Returns a posts builder for general post queries.
return builder.NewGetPostsBuilder(c.RequestContext) return builder.NewGetPostsBuilder(c.RequestContext)
} }
// GetNPosts retrieves a specified number of posts.
func (c *Client) GetNPosts(n int, postBuilder builder.PostsBuilder) ([]model.Post, error) { func (c *Client) GetNPosts(n int, postBuilder builder.PostsBuilder) ([]model.Post, error) {
// Retrieves a specified number of posts using the provided post builder.
if n < utils.E621_MAX_POST_COUNT { if n < utils.E621_MAX_POST_COUNT {
postBuilder.SetLimit(n) postBuilder.SetLimit(n)
} }
@ -125,6 +149,8 @@ func (c *Client) GetNPosts(n int, postBuilder builder.PostsBuilder) ([]model.Pos
return posts, nil return posts, nil
} }
// GetAllPosts retrieves all available posts using the provided post builder.
func (c *Client) GetAllPosts(postBuilder builder.PostsBuilder) ([]model.Post, error) { func (c *Client) GetAllPosts(postBuilder builder.PostsBuilder) ([]model.Post, error) {
// Retrieves all available posts using the provided post builder.
return c.GetNPosts(math.MaxInt, postBuilder) return c.GetNPosts(math.MaxInt, postBuilder)
} }

View File

@ -1,5 +1,4 @@
package utils package utils
const ( // E621_MAX_POST_COUNT is the maximum allowable post count for E621.
E621_MAX_POST_COUNT = 320 const E621_MAX_POST_COUNT = 320
)

View File

@ -2,6 +2,7 @@ package utils
import "fmt" import "fmt"
// StatusCodesToError maps HTTP status codes to corresponding error types.
func StatusCodesToError(statusCode int) error { func StatusCodesToError(statusCode int) error {
var err error var err error
switch statusCode { switch statusCode {
@ -22,83 +23,83 @@ func StatusCodesToError(statusCode int) error {
case 503: case 503:
err = ServiceUnavailableError{} err = ServiceUnavailableError{}
default: default:
err = fmt.Errorf("unhandels status code: %d", statusCode) err = fmt.Errorf("unhandled status code: %d", statusCode)
} }
return err return err
} }
type AccessDeniedError struct { // AccessDeniedError represents an "Access Denied" error.
} type AccessDeniedError struct{}
func (_ AccessDeniedError) Error() string { func (_ AccessDeniedError) Error() string {
return "access denied" return "access denied"
} }
type NotFoundError struct { // NotFoundError represents a "Not Found" error.
} type NotFoundError struct{}
func (_ NotFoundError) Error() string { func (_ NotFoundError) Error() string {
return "not found" return "not found"
} }
type PreconditionFailedError struct { // PreconditionFailedError represents a "Precondition Failed" error.
} type PreconditionFailedError struct{}
func (_ PreconditionFailedError) Error() string { func (_ PreconditionFailedError) Error() string {
return "precondition failed" return "precondition failed"
} }
type RateLimitReachedError struct { // RateLimitReachedError represents a "Rate Limit Reached" error.
} type RateLimitReachedError struct{}
func (_ RateLimitReachedError) Error() string { func (_ RateLimitReachedError) Error() string {
return "rate limit reached" return "rate limit reached"
} }
type InvalidParametersError struct { // InvalidParametersError represents an "Invalid Parameters" error.
} type InvalidParametersError struct{}
func (_ InvalidParametersError) Error() string { func (_ InvalidParametersError) Error() string {
return "invalide parameters" return "invalid parameters"
} }
type InternalServerError struct { // InternalServerError represents an "Internal Server Error" error.
} type InternalServerError struct{}
func (_ InternalServerError) Error() string { func (_ InternalServerError) Error() string {
return "internal server error" return "internal server error"
} }
type BadGatewayError struct { // BadGatewayError represents a "Bad Gateway" error.
} type BadGatewayError struct{}
func (_ BadGatewayError) Error() string { func (_ BadGatewayError) Error() string {
return "bad gateway" return "bad gateway"
} }
type ServiceUnavailableError struct { // ServiceUnavailableError represents a "Service Unavailable" error.
} type ServiceUnavailableError struct{}
func (_ ServiceUnavailableError) Error() string { func (_ ServiceUnavailableError) Error() string {
return "service unavailable" return "service unavailable"
} }
type UnknownError struct { // UnknownError represents an "Unknown" error.
} type UnknownError struct{}
func (_ UnknownError) Error() string { func (_ UnknownError) Error() string {
return "unknown error" return "unknown error"
} }
type OriginConnectionTimeOutError struct { // OriginConnectionTimeOutError represents an "Origin Connection Time-Out" error.
} type OriginConnectionTimeOutError struct{}
func (_ OriginConnectionTimeOutError) Error() string { func (_ OriginConnectionTimeOutError) Error() string {
return "origin connection time-out" return "origin connection time-out"
} }
type SSLHandshakeFailedError struct { // SSLHandshakeFailedError represents an "SSL Handshake Failed" error.
} type SSLHandshakeFailedError struct{}
func (_ SSLHandshakeFailedError) Error() string { func (_ SSLHandshakeFailedError) Error() string {
return "ssl handshake failed" return "ssl handshake failed"