debug.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package api
  2. import (
  3. "time"
  4. "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/api/errs"
  5. )
  6. type DebugStage struct {
  7. DebugEvent `json:",inline"`
  8. Events []*DebugEvent `json:"events"`
  9. }
  10. type DebugEvent struct {
  11. ID string `json:"id"`
  12. Type string `json:"type"`
  13. Status string `json:"status"`
  14. Created int64 `json:"created"`
  15. Error *errs.Error `json:"error"`
  16. Data interface{} `json:"data"`
  17. }
  18. type DebugTaks struct {
  19. ID string `json:"id"`
  20. Status string `json:"status"`
  21. Created int64 `json:"created"`
  22. Stages []*DebugStage `json:"stages"`
  23. CurrentStage *DebugStage `json:"-"`
  24. }
  25. func NewDebugTaks() *DebugTaks {
  26. return &DebugTaks{
  27. Stages: []*DebugStage{},
  28. CurrentStage: &DebugStage{},
  29. }
  30. }
  31. func (debug *DebugTaks) Stage(id string) *DebugStage {
  32. stage := &DebugStage{}
  33. stage.ID = id
  34. debug.CurrentStage = stage
  35. return stage
  36. }
  37. func (stage *DebugStage) PushEvent(event *DebugEvent) {
  38. stage.Events = append(stage.Events, event)
  39. }
  40. func (debug *DebugTaks) Event(eventType, eventId string) *DebugEvent {
  41. event := &DebugEvent{
  42. ID: eventId,
  43. Type: eventType,
  44. Created: time.Now().Unix(),
  45. }
  46. debug.CurrentStage.PushEvent(event)
  47. return event
  48. }
  49. func (debug *DebugTaks) Finalize() {
  50. return
  51. }