You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
934 B

  1. package client
  2. import (
  3. "context"
  4. "fmt"
  5. "git.aiterp.net/lucifer/new-server/models"
  6. )
  7. func (client *Client) GetHandlers(ctx context.Context) ([]models.EventHandler, error) {
  8. handlers := make([]models.EventHandler, 0, 16)
  9. err := client.Fetch(ctx, "GET", "/api/event-handlers", &handlers, nil)
  10. if err != nil {
  11. return nil, err
  12. }
  13. return handlers, nil
  14. }
  15. func (client *Client) AddHandler(ctx context.Context, handler models.EventHandler) (*models.EventHandler, error) {
  16. var result models.EventHandler
  17. err := client.Fetch(ctx, "POST", "/api/event-handlers", &result, handler)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return &result, nil
  22. }
  23. func (client *Client) DeleteHandler(ctx context.Context, id int) (*models.EventHandler, error) {
  24. var handler models.EventHandler
  25. err := client.Fetch(ctx, "DELETE", fmt.Sprintf("/api/event-handlers/%d", id), &handler, nil)
  26. if err != nil {
  27. return nil, err
  28. }
  29. return &handler, nil
  30. }