ucp
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -16,15 +17,21 @@ import (
|
||||
// Currently only CreateOrder is implemented (the from-checkout handoff).
|
||||
// Add GetOrder/ListOrders methods as the backoffice order UI evolves.
|
||||
type OrderClient struct {
|
||||
httpClient *http.Client
|
||||
baseURL string // e.g. "http://order-service:8092"
|
||||
httpClient *http.Client
|
||||
baseURL string // e.g. "http://order-service:8092"
|
||||
agentProfile string // UCP-Agent profile URI
|
||||
}
|
||||
|
||||
// NewOrderClient returns a client that talks to the order service at baseURL.
|
||||
func NewOrderClient(baseURL string) *OrderClient {
|
||||
profile := os.Getenv("UCP_AGENT_PROFILE")
|
||||
if profile == "" {
|
||||
profile = "https://cart.k6n.net/.well-known/ucp"
|
||||
}
|
||||
return &OrderClient{
|
||||
httpClient: &http.Client{Timeout: 30 * time.Second},
|
||||
baseURL: baseURL,
|
||||
httpClient: &http.Client{Timeout: 30 * time.Second},
|
||||
baseURL: baseURL,
|
||||
agentProfile: profile,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +98,7 @@ func (c *OrderClient) CreateOrder(ctx context.Context, req CreateOrderReq, flowN
|
||||
return nil, fmt.Errorf("order client: new request: %w", err)
|
||||
}
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("UCP-Agent", `profile="`+c.agentProfile+`"`)
|
||||
|
||||
resp, err := c.httpClient.Do(httpReq)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user