in capi/capi.go [383:430]
func lintFromCertificateDetails(resp http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
if err != nil {
//@TODO
}
var records model.CCADBRecords
err = json.Unmarshal(body, &records)
if err != nil {
//@TODO
}
answers := make(chan model.ChainLintResult, len(records.CertificateDetails))
work := make(chan model.CCADBRecord, len(records.CertificateDetails))
for _, record := range records.CertificateDetails {
work <- record
}
close(work)
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for record := range work {
answers <- lintSubject(record.TestWebsiteValid)
answers <- lintSubject(record.TestWebsiteExpired)
answers <- lintSubject(record.TestWebsiteRevoked)
}
}()
}
go func() {
wg.Wait()
close(answers)
}()
total := len(records.CertificateDetails) * 3
w := bufio.NewWriter(resp)
w.Write([]byte{'['})
jsonResp := json.NewEncoder(w)
jsonResp.SetIndent("", " ")
i := 0
for answer := range answers {
i++
jsonResp.Encode(answer)
if i < total {
w.Write([]byte{','})
}
}
w.Write([]byte{']'})
w.Flush()
}