rest-end.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package abango
  2. import (
  3. "encoding/json"
  4. "strings"
  5. e "github.com/dabory/abango-rest/etc"
  6. )
  7. //////////// Kafka EndPoint /////////////
  8. func RestRequest(v *AbangoAsk) (string, string, error) {
  9. svars := make(map[string]string)
  10. for _, p := range v.ServerParams {
  11. svars[p.Key] = p.Value
  12. }
  13. apiMethod := strings.ToUpper(svars["api_method"])
  14. if apiMethod == "" { // Default is POST
  15. apiMethod = "POST"
  16. }
  17. askBytes, _ := json.Marshal(&v)
  18. if apiMethod == "POST" {
  19. if retstr, retsta, err := e.GetHttpResponse(apiMethod, XConfig["RestConnect"], askBytes); err == nil {
  20. return string(retstr), string(retsta), nil
  21. } else {
  22. return "", "", err
  23. }
  24. } else if apiMethod == "UPLOAD" {
  25. // httpRtn, statusCode, err = getUploadHttpResponse(apiMethod, _apiUrlPrefix+apiUri, postBytes)
  26. // if err != nil {
  27. // return C.CString(sndrDisconnect(statusCode, err))
  28. // // return sndrDisconnect(statusCode, err)
  29. // }
  30. // }
  31. return "", "", e.MyErr("WERZDDERUVE-api_method not available UPLOAD-["+apiMethod+"]", nil, true)
  32. } else {
  33. return "", "", e.MyErr("WERZDDERUVE-api_method not available ["+apiMethod+"]", nil, true)
  34. }
  35. }