utils.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package modulebase
  15. import (
  16. "io"
  17. "net/http"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/pkg/util/httputils"
  20. "yunion.io/x/pkg/util/printutils"
  21. "yunion.io/x/onecloud/pkg/mcclient"
  22. )
  23. func Get(manager ResourceManager, session *mcclient.ClientSession, path string, respKey string) (jsonutils.JSONObject, error) {
  24. return manager._get(session, path, respKey)
  25. }
  26. func List(manager ResourceManager, session *mcclient.ClientSession, path, respKey string) (*printutils.ListResult, error) {
  27. return manager._list(session, path, respKey)
  28. }
  29. func Head(manager ResourceManager, session *mcclient.ClientSession, path string, respKey string) (jsonutils.JSONObject, error) {
  30. return manager._head(session, path, respKey)
  31. }
  32. func Post(manager ResourceManager, session *mcclient.ClientSession, path string, body jsonutils.JSONObject, respKey string) (jsonutils.JSONObject, error) {
  33. return manager._post(session, path, body, respKey)
  34. }
  35. func Put(manager ResourceManager, session *mcclient.ClientSession, path string, body jsonutils.JSONObject, respKey string) (jsonutils.JSONObject, error) {
  36. return manager._put(session, path, body, respKey)
  37. }
  38. func Patch(manager ResourceManager, session *mcclient.ClientSession, path string, body jsonutils.JSONObject, respKey string) (jsonutils.JSONObject, error) {
  39. return manager._patch(session, path, body, respKey)
  40. }
  41. func Delete(manager ResourceManager, session *mcclient.ClientSession, path string, body jsonutils.JSONObject, respKey string) (jsonutils.JSONObject, error) {
  42. return manager._delete(session, path, body, respKey)
  43. }
  44. func RawRequest(manager ResourceManager, session *mcclient.ClientSession,
  45. method httputils.THttpMethod, path string,
  46. header http.Header, body io.Reader) (*http.Response, error) {
  47. return session.RawVersionRequest(manager.serviceType, manager.endpointType,
  48. method, manager.versionedURL(path),
  49. header, body)
  50. }
  51. func JsonRequest(manager ResourceManager, session *mcclient.ClientSession,
  52. method httputils.THttpMethod, path string,
  53. header http.Header, body jsonutils.JSONObject) (http.Header, jsonutils.JSONObject, error) {
  54. return session.JSONVersionRequest(manager.serviceType, manager.endpointType,
  55. method, manager.versionedURL(path),
  56. header, body)
  57. }