batch

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractMultipleRecords

func ExtractMultipleRecords(results map[string]*RequestResult) ([]map[string]interface{}, error)

Helper method to extract multiple records from batch result

func ExtractRecordData

func ExtractRecordData(result *RequestResult) (map[string]interface{}, error)

Helper method to extract record data from batch result

Types

type BatchBuilder

type BatchBuilder struct {
	// contains filtered or unexported fields
}

BatchBuilder provides a fluent interface for building batch requests

func (*BatchBuilder) AddCustomRequest

func (bb *BatchBuilder) AddCustomRequest(req RestRequest) *BatchBuilder

AddCustomRequest adds a custom request to the batch

func (*BatchBuilder) Create

func (bb *BatchBuilder) Create(id, tableName string, data map[string]interface{}) *BatchBuilder

Create adds a POST request to the batch

func (*BatchBuilder) Delete

func (bb *BatchBuilder) Delete(id, tableName, sysID string) *BatchBuilder

Delete adds a DELETE request to the batch

func (*BatchBuilder) Execute

func (bb *BatchBuilder) Execute() (*BatchResult, error)

Execute executes the batch request

func (*BatchBuilder) ExecuteWithContext

func (bb *BatchBuilder) ExecuteWithContext(ctx context.Context) (*BatchResult, error)

ExecuteWithContext executes the batch request with context support

func (*BatchBuilder) Get

func (bb *BatchBuilder) Get(id, url string) *BatchBuilder

Get adds a GET request to the batch

func (*BatchBuilder) Replace

func (bb *BatchBuilder) Replace(id, tableName, sysID string, data map[string]interface{}) *BatchBuilder

Replace adds a PUT request to the batch

func (*BatchBuilder) Update

func (bb *BatchBuilder) Update(id, tableName, sysID string, data map[string]interface{}) *BatchBuilder

Update adds a PATCH request to the batch

func (*BatchBuilder) WithEnforceOrder

func (bb *BatchBuilder) WithEnforceOrder(enforce bool) *BatchBuilder

WithEnforceOrder enables sequential execution of requests

func (*BatchBuilder) WithRequestID

func (bb *BatchBuilder) WithRequestID(id string) *BatchBuilder

WithRequestID sets a custom batch request ID

type BatchClient

type BatchClient struct {
	// contains filtered or unexported fields
}

BatchClient handles ServiceNow Batch API operations

func NewBatchClient

func NewBatchClient(client *core.Client) *BatchClient

NewBatchClient creates a new batch client

func (*BatchClient) CreateMultiple

func (bc *BatchClient) CreateMultiple(tableName string, records []map[string]interface{}) (*BatchResult, error)

CreateMultiple creates multiple records in a single batch

func (*BatchClient) CreateMultipleWithContext

func (bc *BatchClient) CreateMultipleWithContext(ctx context.Context, tableName string, records []map[string]interface{}) (*BatchResult, error)

CreateMultipleWithContext creates multiple records with context support

func (*BatchClient) DeleteMultiple

func (bc *BatchClient) DeleteMultiple(tableName string, sysIDs []string) (*BatchResult, error)

DeleteMultiple deletes multiple records in a single batch

func (*BatchClient) DeleteMultipleWithContext

func (bc *BatchClient) DeleteMultipleWithContext(ctx context.Context, tableName string, sysIDs []string) (*BatchResult, error)

DeleteMultipleWithContext deletes multiple records with context support

func (*BatchClient) ExecuteMixed

func (bc *BatchClient) ExecuteMixed(operations MixedOperations) (*BatchResult, error)

ExecuteMixed executes mixed operations in a single batch

func (*BatchClient) ExecuteMixedWithContext

func (bc *BatchClient) ExecuteMixedWithContext(ctx context.Context, operations MixedOperations) (*BatchResult, error)

ExecuteMixedWithContext executes mixed operations with context support

func (*BatchClient) GetMultiple

func (bc *BatchClient) GetMultiple(tableName string, sysIDs []string) (*BatchResult, error)

GetMultiple retrieves multiple records in a single batch

func (*BatchClient) GetMultipleWithContext

func (bc *BatchClient) GetMultipleWithContext(ctx context.Context, tableName string, sysIDs []string) (*BatchResult, error)

GetMultipleWithContext retrieves multiple records with context support

func (*BatchClient) NewBatch

func (bc *BatchClient) NewBatch() *BatchBuilder

NewBatch creates a new batch builder

func (*BatchClient) UpdateMultiple

func (bc *BatchClient) UpdateMultiple(tableName string, updates map[string]map[string]interface{}) (*BatchResult, error)

UpdateMultiple updates multiple records in a single batch

func (*BatchClient) UpdateMultipleWithContext

func (bc *BatchClient) UpdateMultipleWithContext(ctx context.Context, tableName string, updates map[string]map[string]interface{}) (*BatchResult, error)

UpdateMultipleWithContext updates multiple records with context support

type BatchRequest

type BatchRequest struct {
	BatchRequestID string        `json:"batch_request_id"`
	EnforceOrder   bool          `json:"enforce_order,omitempty"`
	RestRequests   []RestRequest `json:"rest_requests"`
}

BatchRequest represents the entire batch request payload

type BatchResponse

type BatchResponse struct {
	BatchRequestID     string              `json:"batch_request_id"`
	ServicedRequests   []ServicedRequest   `json:"serviced_requests"`
	UnservicedRequests []UnservicedRequest `json:"unserviced_requests"`
}

BatchResponse represents the response from a batch request

type BatchResult

type BatchResult struct {
	BatchRequestID     string
	TotalRequests      int
	SuccessfulRequests int
	FailedRequests     int
	Results            map[string]*RequestResult
	Errors             map[string]*RequestError
}

BatchResult provides a convenient interface for accessing batch results

func (*BatchResult) GetAllErrors

func (br *BatchResult) GetAllErrors() map[string]*RequestError

GetAllErrors returns all errors

func (*BatchResult) GetAllSuccessful

func (br *BatchResult) GetAllSuccessful() map[string]*RequestResult

GetAllSuccessful returns all successful results

func (*BatchResult) GetError

func (br *BatchResult) GetError(id string) (*RequestError, bool)

GetError returns the error for a specific request ID

func (*BatchResult) GetResult

func (br *BatchResult) GetResult(id string) (*RequestResult, bool)

GetResult returns the result for a specific request ID

func (*BatchResult) HasErrors

func (br *BatchResult) HasErrors() bool

HasErrors returns true if any requests failed

func (*BatchResult) IsSuccess

func (br *BatchResult) IsSuccess(id string) bool

IsSuccess returns true if the request was successful

type CreateOperation

type CreateOperation struct {
	ID        string
	TableName string
	Data      map[string]interface{}
}

CreateOperation represents a create operation

type DeleteOperation

type DeleteOperation struct {
	ID        string
	TableName string
	SysID     string
}

DeleteOperation represents a delete operation

type GetOperation

type GetOperation struct {
	ID        string
	TableName string
	SysID     string
}

GetOperation represents a get operation

type HTTPMethod

type HTTPMethod string

HTTPMethod represents supported HTTP methods for batch requests

const (
	MethodGET    HTTPMethod = "GET"
	MethodPOST   HTTPMethod = "POST"
	MethodPATCH  HTTPMethod = "PATCH"
	MethodPUT    HTTPMethod = "PUT"
	MethodDELETE HTTPMethod = "DELETE"
)
type Header struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Header represents a HTTP header

type MixedOperations

type MixedOperations struct {
	Creates []CreateOperation
	Updates []UpdateOperation
	Deletes []DeleteOperation
	Gets    []GetOperation
}

MixedOperations allows combining different operations in a single batch

type RequestError

type RequestError struct {
	ID          string
	StatusCode  int
	StatusText  string
	ErrorDetail string
}

RequestError represents a failed request

type RequestResult

type RequestResult struct {
	ID            string
	StatusCode    int
	StatusText    string
	Data          map[string]interface{} // Decoded JSON response
	ExecutionTime time.Duration
}

RequestResult represents a successful request result

type RestRequest

type RestRequest struct {
	ID                     string     `json:"id"`
	URL                    string     `json:"url"`
	Method                 HTTPMethod `json:"method"`
	Headers                []Header   `json:"headers,omitempty"`
	Body                   string     `json:"body,omitempty"` // Base64 encoded
	ExcludeResponseHeaders bool       `json:"exclude_response_headers,omitempty"`
}

RestRequest represents an individual request within a batch

type ServicedRequest

type ServicedRequest struct {
	ID            string `json:"id"`
	StatusCode    int    `json:"status_code"`
	StatusText    string `json:"status_text"`
	Body          string `json:"body"` // Base64 encoded
	ExecutionTime int    `json:"execution_time"`
}

ServicedRequest represents a successfully processed request

type UnservicedRequest

type UnservicedRequest struct {
	ID          string `json:"id"`
	StatusCode  int    `json:"status_code"`
	StatusText  string `json:"status_text"`
	ErrorDetail string `json:"error_detail,omitempty"`
}

UnservicedRequest represents a failed request

type UpdateOperation

type UpdateOperation struct {
	ID        string
	TableName string
	SysID     string
	Data      map[string]interface{}
}

UpdateOperation represents an update operation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL