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/pkg/e621/builder/post.go

37 lines
757 B
Go
Raw Normal View History

package builder
import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
"log"
"strconv"
)
type PostBuilder interface {
SetPostID(postID int) PostBuilder
Execute() (*model.Post, error)
}
func NewGetPostBuilder(requestContext model.RequestContext) PostBuilder {
return &getPost{requestContext: requestContext}
}
type getPost struct {
requestContext model.RequestContext
postID int
}
func (g *getPost) SetPostID(postID int) PostBuilder {
g.postID = postID
return g
}
func (g *getPost) Execute() (*model.Post, error) {
post, err := endpoints.GetPost(g.requestContext, strconv.Itoa(g.postID))
if err != nil {
log.Println(err)
return nil, err
}
return &post, nil
}