platform
This commit is contained in:
+2
-1
@@ -47,10 +47,11 @@ ENV CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH}
|
|||||||
# because the renamed git.k6n.net/mats/* modules are not yet published.
|
# because the renamed git.k6n.net/mats/* modules are not yet published.
|
||||||
COPY --from=slaskfinder . ./slask-finder
|
COPY --from=slaskfinder . ./slask-finder
|
||||||
COPY --from=redisinventory . ./go-redis-inventory
|
COPY --from=redisinventory . ./go-redis-inventory
|
||||||
|
COPY --from=platform . ./platform
|
||||||
|
|
||||||
# This module's source (relay on .dockerignore to prune).
|
# This module's source (relay on .dockerignore to prune).
|
||||||
COPY . ./go-cart-actor
|
COPY . ./go-cart-actor
|
||||||
RUN printf 'go 1.26.2\n\nuse (\n\t.\n\t../slask-finder\n\t../go-redis-inventory\n)\n' > ./go-cart-actor/go.work
|
RUN printf 'go 1.26.2\n\nuse (\n\t.\n\t../slask-finder\n\t../go-redis-inventory\n\t../platform\n)\n' > ./go-cart-actor/go.work
|
||||||
WORKDIR /src/go-cart-actor
|
WORKDIR /src/go-cart-actor
|
||||||
|
|
||||||
# (Optional) If you do NOT check in generated protobuf code, uncomment generation:
|
# (Optional) If you do NOT check in generated protobuf code, uncomment generation:
|
||||||
|
|||||||
+4
-10
@@ -9,23 +9,17 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.k6n.net/mats/go-cart-actor/pkg/backofficeadmin"
|
"git.k6n.net/mats/go-cart-actor/pkg/backofficeadmin"
|
||||||
|
"git.k6n.net/mats/platform/config"
|
||||||
amqp "github.com/rabbitmq/amqp091-go"
|
amqp "github.com/rabbitmq/amqp091-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func envOrDefault(key, def string) string {
|
|
||||||
if v := os.Getenv(key); v != "" {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr := envOrDefault("ADDR", ":8080")
|
addr := config.EnvString("ADDR", ":8080")
|
||||||
amqpURL := os.Getenv("AMQP_URL")
|
amqpURL := os.Getenv("AMQP_URL")
|
||||||
|
|
||||||
app, err := backofficeadmin.New(backofficeadmin.Config{
|
app, err := backofficeadmin.New(backofficeadmin.Config{
|
||||||
DataDir: envOrDefault("CART_DIR", "data"),
|
DataDir: config.EnvString("CART_DIR", "data"),
|
||||||
CheckoutDataDir: envOrDefault("CHECKOUT_DIR", "checkout-data"),
|
CheckoutDataDir: config.EnvString("CHECKOUT_DIR", "checkout-data"),
|
||||||
RedisAddress: os.Getenv("REDIS_ADDRESS"),
|
RedisAddress: os.Getenv("REDIS_ADDRESS"),
|
||||||
RedisPassword: os.Getenv("REDIS_PASSWORD"),
|
RedisPassword: os.Getenv("REDIS_PASSWORD"),
|
||||||
})
|
})
|
||||||
|
|||||||
+4
-12
@@ -21,6 +21,7 @@ import (
|
|||||||
"git.k6n.net/mats/go-cart-actor/pkg/telemetry"
|
"git.k6n.net/mats/go-cart-actor/pkg/telemetry"
|
||||||
"git.k6n.net/mats/go-cart-actor/pkg/voucher"
|
"git.k6n.net/mats/go-cart-actor/pkg/voucher"
|
||||||
"git.k6n.net/mats/go-redis-inventory/pkg/inventory"
|
"git.k6n.net/mats/go-redis-inventory/pkg/inventory"
|
||||||
|
"git.k6n.net/mats/platform/config"
|
||||||
"git.k6n.net/mats/slask-finder/pkg/messaging"
|
"git.k6n.net/mats/slask-finder/pkg/messaging"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
@@ -52,7 +53,6 @@ var amqpUrl = os.Getenv("AMQP_URL")
|
|||||||
var redisAddress = os.Getenv("REDIS_ADDRESS")
|
var redisAddress = os.Getenv("REDIS_ADDRESS")
|
||||||
var redisPassword = os.Getenv("REDIS_PASSWORD")
|
var redisPassword = os.Getenv("REDIS_PASSWORD")
|
||||||
|
|
||||||
// getEnv returns the value of the environment variable named by key, or def if unset/empty.
|
|
||||||
// normalizeListenAddr accepts either a bare port ("8080") or a full listen
|
// normalizeListenAddr accepts either a bare port ("8080") or a full listen
|
||||||
// address (":8080", "0.0.0.0:8080") and returns a value usable by http.Server.Addr.
|
// address (":8080", "0.0.0.0:8080") and returns a value usable by http.Server.Addr.
|
||||||
func normalizeListenAddr(v string) string {
|
func normalizeListenAddr(v string) string {
|
||||||
@@ -62,14 +62,6 @@ func normalizeListenAddr(v string) string {
|
|||||||
return ":" + v
|
return ":" + v
|
||||||
}
|
}
|
||||||
|
|
||||||
// getEnv returns the value of the environment variable named by key, or def if unset/empty.
|
|
||||||
func getEnv(key, def string) string {
|
|
||||||
if v := os.Getenv(key); v != "" {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadUCPCartSigner loads the UCP ECDSA signing key from the path specified in
|
// loadUCPCartSigner loads the UCP ECDSA signing key from the path specified in
|
||||||
// the UCP_SIGNING_KEY_PATH environment variable. Returns nil if unset or unreadable.
|
// the UCP_SIGNING_KEY_PATH environment variable. Returns nil if unset or unreadable.
|
||||||
func loadUCPCartSigner() *ucp.SigningConfig {
|
func loadUCPCartSigner() *ucp.SigningConfig {
|
||||||
@@ -129,7 +121,7 @@ func main() {
|
|||||||
// cartPort is the bare HTTP port. It drives both the local listener and the
|
// cartPort is the bare HTTP port. It drives both the local listener and the
|
||||||
// port used to proxy to peer pods, so a cluster must run all pods on the
|
// port used to proxy to peer pods, so a cluster must run all pods on the
|
||||||
// same CART_PORT.
|
// same CART_PORT.
|
||||||
cartPort := getEnv("CART_PORT", "8080")
|
cartPort := config.EnvString("CART_PORT", "8080")
|
||||||
if i := strings.LastIndex(cartPort, ":"); i >= 0 {
|
if i := strings.LastIndex(cartPort, ":"); i >= 0 {
|
||||||
cartPort = cartPort[i+1:]
|
cartPort = cartPort[i+1:]
|
||||||
}
|
}
|
||||||
@@ -226,7 +218,7 @@ func main() {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
diskStorage := actor.NewDiskStorage[cart.CartGrain](getEnv("CART_DIR", "data"), reg)
|
diskStorage := actor.NewDiskStorage[cart.CartGrain](config.EnvString("CART_DIR", "data"), reg)
|
||||||
poolConfig := actor.GrainPoolConfig[cart.CartGrain]{
|
poolConfig := actor.GrainPoolConfig[cart.CartGrain]{
|
||||||
MutationRegistry: reg,
|
MutationRegistry: reg,
|
||||||
Storage: diskStorage,
|
Storage: diskStorage,
|
||||||
@@ -415,7 +407,7 @@ func main() {
|
|||||||
mux.HandleFunc("/openapi.json", ServeEmbeddedOpenAPI)
|
mux.HandleFunc("/openapi.json", ServeEmbeddedOpenAPI)
|
||||||
|
|
||||||
httpAddr := normalizeListenAddr(cartPort)
|
httpAddr := normalizeListenAddr(cartPort)
|
||||||
debugAddr := normalizeListenAddr(getEnv("CART_DEBUG_PORT", "8081"))
|
debugAddr := normalizeListenAddr(config.EnvString("CART_DEBUG_PORT", "8081"))
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: httpAddr,
|
Addr: httpAddr,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
messages "git.k6n.net/mats/go-cart-actor/proto/cart"
|
messages "git.k6n.net/mats/go-cart-actor/proto/cart"
|
||||||
|
"git.k6n.net/mats/platform/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// consumedKeys are product-document keys that are mapped to typed AddItem
|
// consumedKeys are product-document keys that are mapped to typed AddItem
|
||||||
@@ -24,7 +25,7 @@ var consumedKeys = []string{
|
|||||||
// PRODUCT_BASE_URL (the country argument is currently unused but kept for when
|
// PRODUCT_BASE_URL (the country argument is currently unused but kept for when
|
||||||
// per-market routing returns).
|
// per-market routing returns).
|
||||||
func getBaseUrl(country string) string {
|
func getBaseUrl(country string) string {
|
||||||
return getEnv("PRODUCT_BASE_URL", "http://localhost:8082")
|
return config.EnvString("PRODUCT_BASE_URL", "http://localhost:8082")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProductItem is the flat product document served by GET /api/get/{sku}.
|
// ProductItem is the flat product document served by GET /api/get/{sku}.
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
"git.k6n.net/mats/go-cart-actor/pkg/proxy"
|
"git.k6n.net/mats/go-cart-actor/pkg/proxy"
|
||||||
"git.k6n.net/mats/go-cart-actor/pkg/telemetry"
|
"git.k6n.net/mats/go-cart-actor/pkg/telemetry"
|
||||||
"git.k6n.net/mats/go-redis-inventory/pkg/inventory"
|
"git.k6n.net/mats/go-redis-inventory/pkg/inventory"
|
||||||
|
"git.k6n.net/mats/platform/config"
|
||||||
"github.com/adyen/adyen-go-api-library/v21/src/adyen"
|
"github.com/adyen/adyen-go-api-library/v21/src/adyen"
|
||||||
"github.com/adyen/adyen-go-api-library/v21/src/common"
|
"github.com/adyen/adyen-go-api-library/v21/src/common"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@@ -59,19 +60,12 @@ func selectTaxProvider() cart.TaxProvider {
|
|||||||
case "static":
|
case "static":
|
||||||
return cart.NewStaticTaxProvider()
|
return cart.NewStaticTaxProvider()
|
||||||
case "nordic":
|
case "nordic":
|
||||||
return cart.NewNordicTaxProvider(envOrDefault("TAX_DEFAULT_COUNTRY", "SE"))
|
return cart.NewNordicTaxProvider(config.EnvString("TAX_DEFAULT_COUNTRY", "SE"))
|
||||||
default:
|
default:
|
||||||
return cart.NewNordicTaxProvider(envOrDefault("TAX_DEFAULT_COUNTRY", "SE"))
|
return cart.NewNordicTaxProvider(config.EnvString("TAX_DEFAULT_COUNTRY", "SE"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func envOrDefault(key, def string) string {
|
|
||||||
if v := os.Getenv(key); v != "" {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadUCPCheckoutSigner loads the UCP ECDSA signing key from the path specified in
|
// loadUCPCheckoutSigner loads the UCP ECDSA signing key from the path specified in
|
||||||
// the UCP_SIGNING_KEY_PATH environment variable. Returns nil if unset or unreadable.
|
// the UCP_SIGNING_KEY_PATH environment variable. Returns nil if unset or unreadable.
|
||||||
func loadUCPCheckoutSigner() *ucp.SigningConfig {
|
func loadUCPCheckoutSigner() *ucp.SigningConfig {
|
||||||
|
|||||||
+7
-13
@@ -27,6 +27,7 @@ import (
|
|||||||
ordermcp "git.k6n.net/mats/go-cart-actor/pkg/order/mcp"
|
ordermcp "git.k6n.net/mats/go-cart-actor/pkg/order/mcp"
|
||||||
"git.k6n.net/mats/go-cart-actor/pkg/outbox"
|
"git.k6n.net/mats/go-cart-actor/pkg/outbox"
|
||||||
messages "git.k6n.net/mats/go-cart-actor/proto/order"
|
messages "git.k6n.net/mats/go-cart-actor/proto/order"
|
||||||
|
"git.k6n.net/mats/platform/config"
|
||||||
|
|
||||||
"google.golang.org/protobuf/encoding/protojson"
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
@@ -49,9 +50,9 @@ type server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr := envOr("ORDER_ADDR", ":8092") // :8090 cart, :8091 redirector
|
addr := config.EnvString("ORDER_ADDR", ":8092") // :8090 cart, :8091 redirector
|
||||||
dataDir := envOr("ORDER_DATA", "data/orders")
|
dataDir := config.EnvString("ORDER_DATA", "data/orders")
|
||||||
flowsDir := envOr("ORDER_FLOWS", "data/order-flows")
|
flowsDir := config.EnvString("ORDER_FLOWS", "data/order-flows")
|
||||||
if err := os.MkdirAll(dataDir, 0o755); err != nil {
|
if err := os.MkdirAll(dataDir, 0o755); err != nil {
|
||||||
log.Fatalf("create data dir: %v", err)
|
log.Fatalf("create data dir: %v", err)
|
||||||
}
|
}
|
||||||
@@ -154,7 +155,7 @@ func main() {
|
|||||||
mux.HandleFunc("GET /api/orders/{id}", s.handleGet)
|
mux.HandleFunc("GET /api/orders/{id}", s.handleGet)
|
||||||
mux.HandleFunc("GET /api/orders/{id}/events", s.handleEvents)
|
mux.HandleFunc("GET /api/orders/{id}/events", s.handleEvents)
|
||||||
|
|
||||||
// Post-purchase lifecycle (the grain already supports these transitions).
|
// Post-purchase lifecycle (the grain already supports these transitions).
|
||||||
mux.HandleFunc("POST /api/orders/{id}/fulfillments", s.handleFulfill)
|
mux.HandleFunc("POST /api/orders/{id}/fulfillments", s.handleFulfill)
|
||||||
mux.HandleFunc("POST /api/orders/{id}/complete", s.handleComplete)
|
mux.HandleFunc("POST /api/orders/{id}/complete", s.handleComplete)
|
||||||
mux.HandleFunc("POST /api/orders/{id}/cancel", s.handleCancel)
|
mux.HandleFunc("POST /api/orders/{id}/cancel", s.handleCancel)
|
||||||
@@ -462,9 +463,9 @@ func selectTaxProvider() order.TaxProvider {
|
|||||||
case "static":
|
case "static":
|
||||||
return order.NewStaticTaxProvider()
|
return order.NewStaticTaxProvider()
|
||||||
case "nordic":
|
case "nordic":
|
||||||
return order.NewNordicTaxProvider(envOr("TAX_DEFAULT_COUNTRY", "SE"))
|
return order.NewNordicTaxProvider(config.EnvString("TAX_DEFAULT_COUNTRY", "SE"))
|
||||||
default:
|
default:
|
||||||
return order.NewNordicTaxProvider(envOr("TAX_DEFAULT_COUNTRY", "SE"))
|
return order.NewNordicTaxProvider(config.EnvString("TAX_DEFAULT_COUNTRY", "SE"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,13 +506,6 @@ func loadUCPOrderSigner() *ucp.SigningConfig {
|
|||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func envOr(key, def string) string {
|
|
||||||
if v := os.Getenv(key); v != "" {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeJSON(w http.ResponseWriter, status int, v any) {
|
func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
|
|||||||
+3
-10
@@ -19,6 +19,7 @@ import (
|
|||||||
"git.k6n.net/mats/go-cart-actor/pkg/profile"
|
"git.k6n.net/mats/go-cart-actor/pkg/profile"
|
||||||
"git.k6n.net/mats/go-cart-actor/pkg/proxy"
|
"git.k6n.net/mats/go-cart-actor/pkg/proxy"
|
||||||
"git.k6n.net/mats/go-cart-actor/pkg/telemetry"
|
"git.k6n.net/mats/go-cart-actor/pkg/telemetry"
|
||||||
|
"git.k6n.net/mats/platform/config"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||||
)
|
)
|
||||||
@@ -88,18 +89,10 @@ func loadUCPProfileSigner() *ucp.SigningConfig {
|
|||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// getEnv returns the value of the environment variable named by key, or def if unset/empty.
|
|
||||||
func getEnv(key, def string) string {
|
|
||||||
if v := os.Getenv(key); v != "" {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
reg := profile.NewProfileMutationRegistry()
|
reg := profile.NewProfileMutationRegistry()
|
||||||
|
|
||||||
profileDir := getEnv("PROFILE_DIR", "data/profiles")
|
profileDir := config.EnvString("PROFILE_DIR", "data/profiles")
|
||||||
if err := os.MkdirAll(profileDir, 0755); err != nil {
|
if err := os.MkdirAll(profileDir, 0755); err != nil {
|
||||||
log.Printf("warning: could not create profile data directory %s: %v", profileDir, err)
|
log.Printf("warning: could not create profile data directory %s: %v", profileDir, err)
|
||||||
}
|
}
|
||||||
@@ -214,7 +207,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: getEnv("PROFILE_ADDR", ":8080"),
|
Addr: config.EnvString("PROFILE_ADDR", ":8080"),
|
||||||
BaseContext: func(net.Listener) context.Context { return ctx },
|
BaseContext: func(net.Listener) context.Context { return ctx },
|
||||||
ReadTimeout: 10 * time.Second,
|
ReadTimeout: 10 * time.Second,
|
||||||
WriteTimeout: 20 * time.Second,
|
WriteTimeout: 20 * time.Second,
|
||||||
|
|||||||
Reference in New Issue
Block a user