update nested map to flat map
This commit is contained in:
37
test.go
37
test.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"beckn-onix/plugins"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -40,11 +41,35 @@ func validateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "Failed to parse request URL", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// Ensure endpoint trimming to avoid leading slashes
|
||||
endpoint := strings.Trim(u.Path, "/")
|
||||
schemaFileName := fmt.Sprintf("%s.json", endpoint)
|
||||
|
||||
payloadData, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to read payload data", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Initialize an instance of Payload struct
|
||||
var payload Payload
|
||||
err1 := json.Unmarshal(payloadData, &payload)
|
||||
if err1 != nil {
|
||||
http.Error(w, "Failed to parse JSON payload", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Extract the domain, version, and endpoint from the payload and URL
|
||||
domain := payload.Context.Domain
|
||||
version := payload.Context.Version
|
||||
version = fmt.Sprintf("v%s", version)
|
||||
|
||||
endpoint := strings.Trim(u.Path, "/")
|
||||
fmt.Println("Handling request for endpoint:", endpoint)
|
||||
domain = strings.ToLower(domain)
|
||||
domain = strings.ReplaceAll(domain, ":", "_")
|
||||
|
||||
schemaFileName := fmt.Sprintf("%s/%s/%s.json", domain, version, endpoint)
|
||||
fmt.Println("printing schema file name : ", schemaFileName)
|
||||
|
||||
// schemaFileName := fmt.Sprintf("%s.json", endpoint)
|
||||
|
||||
pluginsConfig, err := plugins.LoadPluginsConfig("plugins/config.yaml")
|
||||
if err != nil {
|
||||
@@ -64,12 +89,6 @@ func validateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
payloadData, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to read payload data", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
err = validator.Validate(ctx, payloadData)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user