Documentation
¶
Index ¶
- func Bool(b bool) param.Opt[bool]
- func BoolPtr(v bool) *bool
- func DefaultClientOptions() []option.RequestOption
- func File(rdr io.Reader, filename string, contentType string) file
- func Float(f float64) param.Opt[float64]
- func FloatPtr(v float64) *float64
- func Int(i int64) param.Opt[int64]
- func IntPtr(v int64) *int64
- func Opt[T comparable](v T) param.Opt[T]
- func Ptr[T any](v T) *T
- func String(s string) param.Opt[string]
- func StringPtr(v string) *string
- func Time(t time.Time) param.Opt[time.Time]
- func TimePtr(v time.Time) *time.Time
- type Client
- func (r *Client) Delete(ctx context.Context, path string, params any, res any, ...) error
- func (r *Client) Execute(ctx context.Context, method string, path string, params any, res any, ...) error
- func (r *Client) Get(ctx context.Context, path string, params any, res any, ...) error
- func (r *Client) Patch(ctx context.Context, path string, params any, res any, ...) error
- func (r *Client) Post(ctx context.Context, path string, params any, res any, ...) error
- func (r *Client) Put(ctx context.Context, path string, params any, res any, ...) error
- type Error
- type Order
- type OrderInputParam
- type OrderInputProductParam
- type OrderListParams
- type OrderNewParams
- type OrderProduct
- type OrderService
- func (r *OrderService) Delete(ctx context.Context, orderID string, opts ...option.RequestOption) (err error)
- func (r *OrderService) Get(ctx context.Context, orderID string, opts ...option.RequestOption) (res *Order, err error)
- func (r *OrderService) List(ctx context.Context, query OrderListParams, opts ...option.RequestOption) (res *[]Order, err error)
- func (r *OrderService) New(ctx context.Context, body OrderNewParams, opts ...option.RequestOption) (res *Order, err error)
- func (r *OrderService) Update(ctx context.Context, orderID string, body OrderUpdateParams, ...) (res *Order, err error)
- type OrderStatus
- type OrderUpdate
- type OrderUpdateParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultClientOptions ¶
func DefaultClientOptions() []option.RequestOption
DefaultClientOptions read from the environment (ORDERSAPI_API_KEY, ORDERSAPI_BASE_URL). This should be used to initialize new clients.
func Opt ¶
func Opt[T comparable](v T) param.Opt[T]
Types ¶
type Client ¶
type Client struct {
Options []option.RequestOption
Orders OrderService
}
Client creates a struct with services and top level methods that help with interacting with the ordersapi API. You should not instantiate this client directly, and instead use the NewClient method instead.
func NewClient ¶
func NewClient(opts ...option.RequestOption) (r Client)
NewClient generates a new client with the default option read from the environment (ORDERSAPI_API_KEY, ORDERSAPI_BASE_URL). The option passed in as arguments are applied after these default arguments, and all option will be passed down to the services and requests that this client makes.
func (*Client) Delete ¶
func (r *Client) Delete(ctx context.Context, path string, params any, res any, opts ...option.RequestOption) error
Delete makes a DELETE request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
func (*Client) Execute ¶
func (r *Client) Execute(ctx context.Context, method string, path string, params any, res any, opts ...option.RequestOption) error
Execute makes a request with the given context, method, URL, request params, response, and request options. This is useful for hitting undocumented endpoints while retaining the base URL, auth, retries, and other options from the client.
If a byte slice or an io.Reader is supplied to params, it will be used as-is for the request body.
The params is by default serialized into the body using encoding/json. If your type implements a MarshalJSON function, it will be used instead to serialize the request. If a URLQuery method is implemented, the returned url.Values will be used as query strings to the url.
If your params struct uses param.Field, you must provide either [MarshalJSON], [URLQuery], and/or [MarshalForm] functions. It is undefined behavior to use a struct uses param.Field without specifying how it is serialized.
Any "…Params" object defined in this library can be used as the request argument. Note that 'path' arguments will not be forwarded into the url.
The response body will be deserialized into the res variable, depending on its type:
- A pointer to a *http.Response is populated by the raw response.
- A pointer to a byte array will be populated with the contents of the request body.
- A pointer to any other type uses this library's default JSON decoding, which respects UnmarshalJSON if it is defined on the type.
- A nil value will not read the response body.
For even greater flexibility, see option.WithResponseInto and option.WithResponseBodyInto.
func (*Client) Get ¶
func (r *Client) Get(ctx context.Context, path string, params any, res any, opts ...option.RequestOption) error
Get makes a GET request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
func (*Client) Patch ¶
func (r *Client) Patch(ctx context.Context, path string, params any, res any, opts ...option.RequestOption) error
Patch makes a PATCH request with the given URL, params, and optionally deserializes to a response. See [Execute] documentation on the params and response.
type Order ¶
type Order struct {
// The date and time when the order was created
CreatedAt time.Time `json:"createdAt,required" format:"date-time"`
// The unique identifier for the order
OrderID string `json:"orderId,required" format:"uuid"`
// The list of products in the order
Products []OrderProduct `json:"products,required"`
// The status of the order
//
// Any of "OrderPending", "OrderProcessing", "OrderShipped", "OrderDelivered",
// "OrderCancelled".
Status OrderStatus `json:"status,required"`
// The total amount of the order
TotalAmount float64 `json:"totalAmount,required"`
// The user who placed the order
User string `json:"user,required" format:"string"`
// The version of the order
Version int64 `json:"version,required"`
// The date and time when the order was last updated
UpdatedAt time.Time `json:"updatedAt" format:"date-time"`
// The list of updates made to the order
Updates []OrderUpdate `json:"updates"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
OrderID respjson.Field
Products respjson.Field
Status respjson.Field
TotalAmount respjson.Field
User respjson.Field
Version respjson.Field
UpdatedAt respjson.Field
Updates respjson.Field
ExtraFields map[string]respjson.Field
// contains filtered or unexported fields
} `json:"-"`
}
Object representing an order in the system.
func (*Order) UnmarshalJSON ¶
type OrderInputParam ¶
type OrderInputParam struct {
// The list of products in the order
Products []OrderInputProductParam `json:"products,omitzero,required"`
// contains filtered or unexported fields
}
Object representing the input data for creating or updating an order.
The property Products is required.
func (OrderInputParam) MarshalJSON ¶
func (r OrderInputParam) MarshalJSON() (data []byte, err error)
func (*OrderInputParam) UnmarshalJSON ¶
func (r *OrderInputParam) UnmarshalJSON(data []byte) error
type OrderInputProductParam ¶
type OrderInputProductParam struct {
// The name of the product
Name param.Opt[string] `json:"name,omitzero" format:"string"`
// The price of the product
Price param.Opt[float64] `json:"price,omitzero"`
// No.of items
Quantity param.Opt[float64] `json:"quantity,omitzero"`
// contains filtered or unexported fields
}
Object representing the input data for creating or updating a product belonging to an order.
func (OrderInputProductParam) MarshalJSON ¶
func (r OrderInputProductParam) MarshalJSON() (data []byte, err error)
func (*OrderInputProductParam) UnmarshalJSON ¶
func (r *OrderInputProductParam) UnmarshalJSON(data []byte) error
type OrderListParams ¶
type OrderListParams struct {
// Maximum number of items to return
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Number of items to skip
Offset param.Opt[int64] `query:"offset,omitzero" json:"-"`
// contains filtered or unexported fields
}
func (OrderListParams) URLQuery ¶
func (r OrderListParams) URLQuery() (v url.Values, err error)
URLQuery serializes OrderListParams's query parameters as `url.Values`.
type OrderNewParams ¶
type OrderNewParams struct {
// Object representing the input data for creating or updating an order.
OrderInput OrderInputParam
// contains filtered or unexported fields
}
func (OrderNewParams) MarshalJSON ¶
func (r OrderNewParams) MarshalJSON() (data []byte, err error)
func (*OrderNewParams) UnmarshalJSON ¶
func (r *OrderNewParams) UnmarshalJSON(data []byte) error
type OrderProduct ¶
type OrderProduct struct {
// The name of the product
Name string `json:"name" format:"string"`
// The price of the product
Price float64 `json:"price"`
// Additional remarks or description about the product
Remarks string `json:"remarks" format:"string"`
// The status of the product
Status string `json:"status" format:"string"`
// The date and time when the product information was last updated
UpdatedAt time.Time `json:"updatedAt" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Name respjson.Field
Price respjson.Field
Remarks respjson.Field
Status respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
// contains filtered or unexported fields
} `json:"-"`
}
Object representing a product in the system.
func (OrderProduct) RawJSON ¶
func (r OrderProduct) RawJSON() string
Returns the unmodified JSON received from the API
func (*OrderProduct) UnmarshalJSON ¶
func (r *OrderProduct) UnmarshalJSON(data []byte) error
type OrderService ¶
type OrderService struct {
Options []option.RequestOption
}
OrderService contains methods and other services that help with interacting with the ordersapi API.
Note, unlike clients, this service does not read variables from the environment automatically. You should not instantiate this service directly, and instead use the NewOrderService method instead.
func NewOrderService ¶
func NewOrderService(opts ...option.RequestOption) (r OrderService)
NewOrderService generates a new service that applies the given options to each request. These options are applied after the parent client's options (if there is one), and before any request-specific options.
func (*OrderService) Delete ¶
func (r *OrderService) Delete(ctx context.Context, orderID string, opts ...option.RequestOption) (err error)
Delete a specific order by ID
func (*OrderService) Get ¶
func (r *OrderService) Get(ctx context.Context, orderID string, opts ...option.RequestOption) (res *Order, err error)
Retrieve details of a specific order by ID
func (*OrderService) List ¶
func (r *OrderService) List(ctx context.Context, query OrderListParams, opts ...option.RequestOption) (res *[]Order, err error)
Retrieve a list of orders in the system with pagination support
func (*OrderService) New ¶
func (r *OrderService) New(ctx context.Context, body OrderNewParams, opts ...option.RequestOption) (res *Order, err error)
Create a new order in the system
func (*OrderService) Update ¶
func (r *OrderService) Update(ctx context.Context, orderID string, body OrderUpdateParams, opts ...option.RequestOption) (res *Order, err error)
Update details of a specific order by ID
type OrderStatus ¶
type OrderStatus string
The status of the order
const ( OrderStatusOrderPending OrderStatus = "OrderPending" OrderStatusOrderProcessing OrderStatus = "OrderProcessing" OrderStatusOrderShipped OrderStatus = "OrderShipped" OrderStatusOrderDelivered OrderStatus = "OrderDelivered" OrderStatusOrderCancelled OrderStatus = "OrderCancelled" )
type OrderUpdate ¶
type OrderUpdate struct {
// The person or system who handled the update
HandledBy string `json:"handledBy" format:"string"`
// Additional notes or comments about the update
Notes string `json:"notes" format:"string"`
// The date and time when the order was updated
UpdatedAt time.Time `json:"updatedAt" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
HandledBy respjson.Field
Notes respjson.Field
UpdatedAt respjson.Field
ExtraFields map[string]respjson.Field
// contains filtered or unexported fields
} `json:"-"`
}
Object representing an update to an order.
func (OrderUpdate) RawJSON ¶
func (r OrderUpdate) RawJSON() string
Returns the unmodified JSON received from the API
func (*OrderUpdate) UnmarshalJSON ¶
func (r *OrderUpdate) UnmarshalJSON(data []byte) error
type OrderUpdateParams ¶
type OrderUpdateParams struct {
// Object representing the input data for creating or updating an order.
OrderInput OrderInputParam
// contains filtered or unexported fields
}
func (OrderUpdateParams) MarshalJSON ¶
func (r OrderUpdateParams) MarshalJSON() (data []byte, err error)
func (*OrderUpdateParams) UnmarshalJSON ¶
func (r *OrderUpdateParams) UnmarshalJSON(data []byte) error
Directories
¶
| Path | Synopsis |
|---|---|
|
encoding/json
Package json implements encoding and decoding of JSON as defined in RFC 7159.
|
Package json implements encoding and decoding of JSON as defined in RFC 7159. |
|
encoding/json/shims
This package provides shims over Go 1.2{2,3} APIs which are missing from Go 1.21, and used by the Go 1.24 encoding/json package.
|
This package provides shims over Go 1.2{2,3} APIs which are missing from Go 1.21, and used by the Go 1.24 encoding/json package. |
|
packages
|
|
|
shared
|
|