Przeglądaj źródła

Merge pull request #217 from rod-hynes/master

Workaround for requestJSONObject vs. map[string]interface{} type issue
Rod Hynes 9 lat temu
rodzic
commit
2d2d231c6f
2 zmienionych plików z 3 dodań i 3 usunięć
  1. 2 2
      psiphon/server/api.go
  2. 1 1
      psiphon/server/webServer.go

+ 2 - 2
psiphon/server/api.go

@@ -587,7 +587,7 @@ func getJSONObjectRequestParam(params requestJSONObject, name string) (requestJS
 	if params[name] == nil {
 	if params[name] == nil {
 		return nil, common.ContextError(fmt.Errorf("missing param: %s", name))
 		return nil, common.ContextError(fmt.Errorf("missing param: %s", name))
 	}
 	}
-	// TODO: can't use requestJSONObject type?
+	// Note: generic unmarshal of JSON produces map[string]interface{}, not requestJSONObject
 	value, ok := params[name].(map[string]interface{})
 	value, ok := params[name].(map[string]interface{})
 	if !ok {
 	if !ok {
 		return nil, common.ContextError(fmt.Errorf("invalid param: %s", name))
 		return nil, common.ContextError(fmt.Errorf("invalid param: %s", name))
@@ -606,7 +606,7 @@ func getJSONObjectArrayRequestParam(params requestJSONObject, name string) ([]re
 
 
 	result := make([]requestJSONObject, len(value))
 	result := make([]requestJSONObject, len(value))
 	for i, item := range value {
 	for i, item := range value {
-		// TODO: can't use requestJSONObject type?
+		// Note: generic unmarshal of JSON produces map[string]interface{}, not requestJSONObject
 		resultItem, ok := item.(map[string]interface{})
 		resultItem, ok := item.(map[string]interface{})
 		if !ok {
 		if !ok {
 			return nil, common.ContextError(fmt.Errorf("invalid param: %s", name))
 			return nil, common.ContextError(fmt.Errorf("invalid param: %s", name))

+ 1 - 1
psiphon/server/webServer.go

@@ -194,7 +194,7 @@ func convertHTTPRequestToAPIRequest(
 		if err != nil {
 		if err != nil {
 			return nil, common.ContextError(err)
 			return nil, common.ContextError(err)
 		}
 		}
-		var bodyParams requestJSONObject
+		var bodyParams map[string]interface{}
 		err = json.Unmarshal(body, &bodyParams)
 		err = json.Unmarshal(body, &bodyParams)
 		if err != nil {
 		if err != nil {
 			return nil, common.ContextError(err)
 			return nil, common.ContextError(err)