github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/get_subscriptions_command.go (about)

     1  package ravendb
     2  
     3  import (
     4  	"net/http"
     5  	"strconv"
     6  )
     7  
     8  var (
     9  	_ RavenCommand = &GetSubscriptionsCommand{}
    10  )
    11  
    12  // GetSubscriptionsCommand describes "delete subscription" command
    13  type GetSubscriptionsCommand struct {
    14  	RavenCommandBase
    15  
    16  	start    int
    17  	pageSize int
    18  
    19  	Result []*SubscriptionState
    20  }
    21  
    22  func newGetSubscriptionsCommand(start int, pageSize int) *GetSubscriptionsCommand {
    23  	cmd := &GetSubscriptionsCommand{
    24  		RavenCommandBase: NewRavenCommandBase(),
    25  
    26  		start:    start,
    27  		pageSize: pageSize,
    28  	}
    29  	cmd.IsReadRequest = true
    30  	return cmd
    31  }
    32  
    33  func (c *GetSubscriptionsCommand) CreateRequest(node *ServerNode) (*http.Request, error) {
    34  	url := node.URL + "/databases/" + node.Database + "/subscriptions?start=" + strconv.Itoa(c.start) + "&pageSize=" + strconv.Itoa(c.pageSize)
    35  
    36  	return newHttpGet(url)
    37  }
    38  
    39  func (c *GetSubscriptionsCommand) SetResponse(response []byte, fromCache bool) error {
    40  	if len(response) == 0 {
    41  		return nil
    42  	}
    43  	var res *GetSubscriptionsResult
    44  	if err := jsonUnmarshal(response, &res); err != nil {
    45  		return err
    46  	}
    47  	c.Result = res.Results
    48  	return nil
    49  }