-
Notifications
You must be signed in to change notification settings - Fork 1
/
get.go
40 lines (33 loc) · 819 Bytes
/
get.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
package handler
import (
"encoding/json"
"net/http"
"github.com/divpro/cve/internal/service/get"
"github.com/divpro/cve/internal/entity/cve"
"github.com/go-chi/chi"
"github.com/rs/zerolog/log"
)
func GetById(getSVC get.Service) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
source := q.Get("source")
pkg := q.Get("pkg")
id := chi.URLParam(r, "id")
models, err := getSVC.GetByID(r.Context(), &cve.FindFilter{
ID: id,
Package: pkg,
Source: source,
})
if err != nil {
log.Error().Err(err).Msg("db find cve")
w.WriteHeader(http.StatusInternalServerError)
return
}
enc := json.NewEncoder(w)
enc.SetIndent("\t", "")
err = enc.Encode(models)
if err != nil {
log.Error().Err(err).Msg("encode cve response")
}
}
}