summaryrefslogtreecommitdiff
path: root/api/whois/whois.go
blob: a30661dee60b0d83080defe370a1fa8eea1e260d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
	}
}