Skip to content
Snippets Groups Projects

Full MVC of gitlab-zoekt-indexer

Merged Dylan Griffith requested to merge add-new-api-paths into main
All threads resolved!
Compare and Show latest version
1 file
+ 9
6
Compare changes
  • Side-by-side
  • Inline
@@ -6,7 +6,6 @@ import (
@@ -6,7 +6,6 @@ import (
"errors"
"errors"
"flag"
"flag"
"fmt"
"fmt"
"io"
"log"
"log"
"net/http"
"net/http"
"os"
"os"
@@ -98,14 +97,18 @@ func (s *indexServer) handleMetrics() http.HandlerFunc {
@@ -98,14 +97,18 @@ func (s *indexServer) handleMetrics() http.HandlerFunc {
}
}
}
}
 
func (s *indexServer) decode(r *http.Request, v interface{}) error {
 
dec := json.NewDecoder(r.Body)
 
dec.DisallowUnknownFields()
 
return dec.Decode(v)
 
}
 
func (s *indexServer) handleIndex() http.HandlerFunc {
func (s *indexServer) handleIndex() http.HandlerFunc {
route := "index"
route := "index"
parseRequest := func(r io.Reader) (indexRequest, error) {
parseRequest := func(r *http.Request) (indexRequest, error) {
dec := json.NewDecoder(r)
dec.DisallowUnknownFields()
var req indexRequest
var req indexRequest
err := dec.Decode(&req)
err := s.decode(r, &req)
if err != nil {
if err != nil {
return req, errors.New("json parser error")
return req, errors.New("json parser error")
@@ -123,7 +126,7 @@ func (s *indexServer) handleIndex() http.HandlerFunc {
@@ -123,7 +126,7 @@ func (s *indexServer) handleIndex() http.HandlerFunc {
}
}
return func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
req, err := parseRequest(r.Body)
req, err := parseRequest(r)
if err != nil {
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
http.Error(w, err.Error(), http.StatusBadRequest)
return
return
Loading