script.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package adapter
  2. import (
  3. "context"
  4. "net/http"
  5. )
  6. type ScriptManager interface {
  7. Lifecycle
  8. Scripts() []Script
  9. // Script(name string) (Script, bool)
  10. }
  11. type Script interface {
  12. Type() string
  13. Tag() string
  14. StartContext(ctx context.Context, startContext *HTTPStartContext) error
  15. PostStart() error
  16. Close() error
  17. }
  18. type GenericScript interface {
  19. Script
  20. Run(ctx context.Context) error
  21. }
  22. type HTTPScript interface {
  23. Script
  24. Match(requestURL string) bool
  25. RequiresBody() bool
  26. MaxSize() int64
  27. }
  28. type HTTPRequestScript interface {
  29. HTTPScript
  30. Run(ctx context.Context, request *http.Request, body []byte) (*HTTPRequestScriptResult, error)
  31. }
  32. type HTTPRequestScriptResult struct {
  33. URL string
  34. Headers http.Header
  35. Body []byte
  36. Response *HTTPRequestScriptResponse
  37. }
  38. type HTTPRequestScriptResponse struct {
  39. Status int
  40. Headers http.Header
  41. Body []byte
  42. }
  43. type HTTPResponseScript interface {
  44. HTTPScript
  45. Run(ctx context.Context, request *http.Request, response *http.Response, body []byte) (*HTTPResponseScriptResult, error)
  46. }
  47. type HTTPResponseScriptResult struct {
  48. Status int
  49. Headers http.Header
  50. Body []byte
  51. }