-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_list.go
42 lines (39 loc) · 833 Bytes
/
api_list.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2021 Sean.ZH
package main
import (
"log"
"net/http"
)
func (a *ApiHandler) ListRecord(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
log.Println("list record bad method:", r.Method)
w.Write(a.BadMethodMsg)
return
}
var record DNSRecord
err := a.UnjsonRequest(r, &record)
if err != nil {
log.Println("bad request:", err)
w.Write(a.BadRequestMsg)
return
}
// for good check
record.Ttl = 100
err = CommonCheck(&record)
if err != nil {
log.Println("bad common check:", record)
w.Write(a.BadRecordValue)
return
}
ret, err := a.DB.Find(record.Name, record.Type)
if err != nil {
log.Println("find error:", err)
w.Write(a.DBErrMsg)
return
}
// empty result, make an empty slice
if len(ret) == 0 {
ret = make([]DNSRecord, 0)
}
a.JsonResponse(w, ret)
}