@@ -73,47 +73,47 @@ func main() {
73
73
server .AddPrometheusHandler ()
74
74
75
75
// Enable services in this instance. Services are enabled with the following logic:
76
- // If QUICKPIZZA_ALL_SERVICES is either _not set_ or set to a truthy value, all services are enabled. This is the
76
+ // If QUICKPIZZA_ENABLE_ALL_SERVICES is either _not set_ or set to a truthy value, all services are enabled. This is the
77
77
// default behavior.
78
- // If QUICKPIZZA_ALL_SERVICES is set to a falsy values, services are opted-in by setting the environment variables
78
+ // If QUICKPIZZA_ENABLE_ALL_SERVICES is set to a falsy values, services are opted-in by setting the environment variables
79
79
// below to a truty value.
80
80
81
- if envServe ("QUICKPIZZA_HTTP_TESTING " ) {
81
+ if envServe ("QUICKPIZZA_ENABLE_HTTP_TESTING_SERVICE " ) {
82
82
server .AddHTTPTesting ()
83
83
}
84
84
85
- if envServe ("QUICKPIZZA_TEST_K6_IO " ) {
85
+ if envServe ("QUICKPIZZA_ENABLE_TEST_K6_IO_SERVICE " ) {
86
86
server .AddTestK6IO ()
87
87
}
88
88
89
- if envServe ("QUICKPIZZA_CONFIG " ) {
89
+ if envServe ("QUICKPIZZA_ENABLE_CONFIG_SERVICE " ) {
90
90
// Prefix for env vars is QUICKPIZZA_CONF_ instead of QUICKPIZZA_CONFIG_ to avoid picking up variables
91
91
// generated by K8s from the pod name.
92
92
server .AddConfigHandler (envConfig ("QUICKPIZZA_CONF_" ))
93
93
}
94
94
95
- if envServe ("QUICKPIZZA_FRONTEND " ) {
95
+ if envServe ("QUICKPIZZA_ENABLE_PUBLIC_API_SERVICE " ) {
96
96
// Serve frontend static assets
97
97
server .AddFrontend ()
98
98
99
99
// If running as a microservice (not all services in one instance),
100
100
// also act as a gateway to proxy public-facing endpoints
101
101
if ! envServeAll () {
102
102
server .AddGateway (
103
- envEndpoint ("QUICKPIZZA_CATALOG " ),
104
- envEndpoint ("QUICKPIZZA_COPY " ),
105
- envEndpoint ("QUICKPIZZA_WS " ),
106
- envEndpoint ("QUICKPIZZA_RECOMMENDATIONS " ),
107
- envEndpoint ("QUICKPIZZA_CONFIG " ),
103
+ envEndpoint ("QUICKPIZZA_ENABLE_CATALOG_SERVICE" , "QUICKPIZZA_CATALOG_ENDPOINT " ),
104
+ envEndpoint ("QUICKPIZZA_ENABLE_COPY_SERVICE" , "QUICKPIZZA_COPY_ENDPOINT " ),
105
+ envEndpoint ("QUICKPIZZA_ENABLE_WS_SERVICE" , "QUICKPIZZA_WS_ENDPOINT " ),
106
+ envEndpoint ("QUICKPIZZA_ENABLE_RECOMMENDATIONS_SERVICE" , "QUICKPIZZA_RECOMMENDATIONS_ENDPOINT " ),
107
+ envEndpoint ("QUICKPIZZA_ENABLE_CONFIG_SERVICE" , "QUICKPIZZA_CONFIG_ENDPOINT " ),
108
108
)
109
109
}
110
110
}
111
111
112
- if envServe ("QUICKPIZZA_WS " ) {
112
+ if envServe ("QUICKPIZZA_ENABLE_WS_SERVICE " ) {
113
113
server .AddWebSocket ()
114
114
}
115
115
116
- if envServe ("QUICKPIZZA_CATALOG " ) {
116
+ if envServe ("QUICKPIZZA_ENABLE_CATALOG_SERVICE " ) {
117
117
db , err := database .NewCatalog (envDBConnString ())
118
118
if err != nil {
119
119
slog .Error ("setting up database connection" , "err" , err )
@@ -122,7 +122,7 @@ func main() {
122
122
server .AddCatalogHandler (db )
123
123
}
124
124
125
- if envServe ("QUICKPIZZA_COPY " ) {
125
+ if envServe ("QUICKPIZZA_ENABLE_COPY_SERVICE " ) {
126
126
db , err := database .NewCopy (envDBConnString ())
127
127
if err != nil {
128
128
slog .Error ("setting up database connection" , "err" , err )
@@ -134,14 +134,14 @@ func main() {
134
134
// Recommendations service needs to know the URL where the Catalog and Copy services are located.
135
135
// This URL is automatically set to `localhost` if Recommendations is enabled at the same time as either of those.
136
136
// If they are not, URLs are sourced from QUICKPIZZA_CATALOG_ENDPOINT and QUICKPIZZA_COPY_ENDPOINT.
137
- if envServe ("QUICKPIZZA_RECOMMENDATIONS " ) {
138
- catalogClient := qphttp .NewCatalogClient (envEndpoint ("QUICKPIZZA_CATALOG " )).WithClient (httpCli )
139
- copyClient := qphttp .NewCopyClient (envEndpoint ("QUICKPIZZA_COPY " )).WithClient (httpCli )
137
+ if envServe ("QUICKPIZZA_ENABLE_RECOMMENDATIONS_SERVICE " ) {
138
+ catalogClient := qphttp .NewCatalogClient (envEndpoint ("QUICKPIZZA_ENABLE_CATALOG_SERVICE" , "QUICKPIZZA_CATALOG_ENDPOINT " )).WithClient (httpCli )
139
+ copyClient := qphttp .NewCopyClient (envEndpoint ("QUICKPIZZA_ENABLE_COPY_SERVICE" , "QUICKPIZZA_COPY_ENDPOINT " )).WithClient (httpCli )
140
140
141
141
server .AddRecommendations (catalogClient , copyClient )
142
142
}
143
143
144
- if envServe ("QUICKPIZZA_GRPC " ) {
144
+ if envServe ("QUICKPIZZA_ENABLE_GRPC_SERVICE " ) {
145
145
grpcServer := qpgrpc .NewServer (":3334" , ":3335" )
146
146
go func () {
147
147
err := grpcServer .ListenAndServe ()
@@ -263,15 +263,15 @@ func envPyroscopeConfig() (pyroscope.Config, bool) {
263
263
}
264
264
265
265
func envServeAll () bool {
266
- allSvcs , present := os .LookupEnv ("QUICKPIZZA_ALL_SERVICES " )
266
+ allSvcs , present := os .LookupEnv ("QUICKPIZZA_ENABLE_ALL_SERVICES " )
267
267
allSvcsB , _ := strconv .ParseBool (allSvcs )
268
268
269
- // If QUICKPIZZA_ALL_SERVICES is not defined (default), serve everything.
269
+ // If QUICKPIZZA_ENABLE_ALL_SERVICES is not defined (default), serve everything.
270
270
if ! present {
271
271
return true
272
272
}
273
273
274
- // Otherwise, serve all if QUICKPIZZA_ALL_SERVICES is truthy.
274
+ // Otherwise, serve all if QUICKPIZZA_ENABLE_ALL_SERVICES is truthy.
275
275
return allSvcsB
276
276
}
277
277
@@ -280,14 +280,15 @@ func envServe(name string) bool {
280
280
return envServeAll () || envBool (name )
281
281
}
282
282
283
- // envEndpoint returns the endpoint for a given service. If the service is enabled in this instance, it returns
284
- // `localhost`. If it isn't, it returns the value of QUICKPIZZA_SERVICENAME_ENDPOINT.fs
285
- func envEndpoint (name string ) string {
286
- if envServe (name ) {
283
+ // envEndpoint returns the endpoint URL for a service.
284
+ // If the service is enabled (envServe(svcEnv) == true), it returns "http://localhost:3333".
285
+ // Otherwise, it returns the value of the endpointEnv environment variable.
286
+ func envEndpoint (svcEnv , endpointEnv string ) string {
287
+ if envServe (svcEnv ) {
287
288
return "http://localhost:3333"
288
289
}
289
290
290
- endpoint , _ := os .LookupEnv (name + "_ENDPOINT" )
291
+ endpoint , _ := os .LookupEnv (endpointEnv )
291
292
return endpoint
292
293
}
293
294
0 commit comments