|
@@ -6,6 +6,7 @@ import (
|
|
|
"io"
|
|
"io"
|
|
|
"net"
|
|
"net"
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
+ "reflect"
|
|
|
"time"
|
|
"time"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -122,13 +123,17 @@ func (this *HTTPServer) ServeHTTP(responseStream http.ResponseWriter, requestStr
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- handler, ok := this.handlers[HTTPServerAction{Method: method, Path: requestStream.URL.Path}]
|
|
|
|
|
|
|
+ handlerSpec, ok := this.handlers[HTTPServerAction{Method: method, Path: requestStream.URL.Path}]
|
|
|
if !ok {
|
|
if !ok {
|
|
|
this.log.Error("handler not found", LogValue("path", requestStream.URL.Path))
|
|
this.log.Error("handler not found", LogValue("path", requestStream.URL.Path))
|
|
|
responseStream.WriteHeader(http.StatusInternalServerError)
|
|
responseStream.WriteHeader(http.StatusInternalServerError)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ handler := HTTPServerHandler{}
|
|
|
|
|
+ copyStruct(handler, handlerSpec)
|
|
|
|
|
+ handlerSpec = handler
|
|
|
|
|
+
|
|
|
// Parse GET query
|
|
// Parse GET query
|
|
|
if method == METHOD_GET && handler.Data != nil {
|
|
if method == METHOD_GET && handler.Data != nil {
|
|
|
query := map[string]any{}
|
|
query := map[string]any{}
|
|
@@ -249,3 +254,32 @@ func (this *HTTPServer) ServeHTTP(responseStream http.ResponseWriter, requestStr
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func copyStruct(dst interface{}, src interface{}) {
|
|
|
|
|
+ dstVal := reflect.ValueOf(dst)
|
|
|
|
|
+ srcVal := reflect.ValueOf(src)
|
|
|
|
|
+
|
|
|
|
|
+ if dstVal.Kind() != reflect.Ptr || dstVal.Elem().Kind() != reflect.Struct {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if srcVal.Kind() == reflect.Ptr {
|
|
|
|
|
+ srcVal = srcVal.Elem()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if srcVal.Kind() != reflect.Struct {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ dstVal = dstVal.Elem()
|
|
|
|
|
+ for i := 0; i < srcVal.NumField(); i++ {
|
|
|
|
|
+ srcField := srcVal.Field(i)
|
|
|
|
|
+ fieldName := srcVal.Type().Field(i).Name
|
|
|
|
|
+
|
|
|
|
|
+ dstField := dstVal.FieldByName(fieldName)
|
|
|
|
|
+
|
|
|
|
|
+ if dstField.IsValid() && dstField.CanSet() && dstField.Type() == srcField.Type() {
|
|
|
|
|
+ dstField.Set(srcField)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|