model.go 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package plugin
  2. import (
  3. "encoding/json"
  4. )
  5. type GraphRequestLine struct {
  6. Method string `json:"method"`
  7. Uri string `json:"uri"`
  8. }
  9. type GraphRequest struct {
  10. RequestLine GraphRequestLine `json:"requestLine"`
  11. Headers map[string]string `json:"headers"`
  12. Body string `json:"body"`
  13. }
  14. type GraphStatusLine struct {
  15. Code int `json:"code"`
  16. Reason string `json:"reasonPhrase"`
  17. }
  18. type GraphResponse struct {
  19. StatusLine GraphStatusLine `json:"statusLine"`
  20. Headers map[string]string `json:"headers"`
  21. Body string `json:"body"`
  22. }
  23. // 用于将数据转换成插件的请求参数
  24. func (req *GraphRequest) ParseRequest(pluginRequest interface{}) error {
  25. data, err := json.Marshal(req.Body)
  26. if err != nil {
  27. return err
  28. }
  29. err = json.Unmarshal(data, pluginRequest)
  30. if err != nil {
  31. return err
  32. }
  33. return nil
  34. }
  35. type PluginResponse struct {
  36. Result interface{} `json:"result"`
  37. RequestId string `json:"requestId"`
  38. }