diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/whois/whois.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/api/whois/whois.go b/api/whois/whois.go new file mode 100644 index 0000000..a30661d --- /dev/null +++ b/api/whois/whois.go @@ -0,0 +1,28 @@ +package whois + +import ( + "log" + "net/http" + + "git.simponic.xyz/simponic/whois/api/types" + "git.simponic.xyz/simponic/whois/database" +) + +func FetchLatestName(context *types.RequestContext, req *http.Request, resp http.ResponseWriter) types.ContinuationChain { + return func(success types.Continuation, failure types.Continuation) types.ContinuationChain { + updates, err := database.ListUpdates(context.DBConn, database.ListUpdatesQuery{Limit: 1}) + if err != nil { + log.Printf("err fetching updates %s", err) + resp.WriteHeader(http.StatusInternalServerError) + return failure(context, req, resp) + } + if len(updates) == 0 { + log.Printf("no updates yet") + resp.WriteHeader(http.StatusNotFound) + return failure(context, req, resp) + } + + (*context.TemplateData)["Latest"] = updates[0] + return success(context, req, resp) + } +} |