gcp library
Classes
- RequestLogger
- Allows logging at a specified severity.
Enums
Constants
- cloudTraceContextHeader → const String
- Standard header used by Cloud Trace.
- defaultListenPort → const int
- The default port a service should listen on if portEnvironmentKey is not set.
-
gcpProjectIdEnvironmentVariables
→ const Set<
String> - A set of typical environment variables that are likely to represent the current Google Cloud project ID.
- portEnvironmentKey → const String
- The standard environment variable for specifying the port a service should listen on.
Properties
- badRequestMiddleware → Middleware
-
Adds logic which catches BadRequestException, logs details to stderr and
returns a corresponding
Response
.no setter - currentLogger → RequestLogger
-
Returns the current RequestLogger.
no setter
Functions
-
cloudLoggingMiddleware(
String projectId) → Middleware -
Return
Middleware
that logs errors using Google Cloud structured logs and returns the correct response. -
computeProjectId(
) → Future< String> -
A convenience wrapper that first tries projectIdFromEnvironment
then (if the value is
null
) tries projectIdFromMetadataServer -
createLoggingMiddleware(
{String? projectId}) → Middleware -
Convenience
Middleware
that handles logging depending onprojectId
. -
listenPort(
) → int -
Returns the port to listen on from environment variable or uses the default
8080
. -
projectIdFromEnvironment(
) → String? - Returns the Project ID for the current Google Cloud Project by checking the environment variables in gcpProjectIdEnvironmentVariables.
-
projectIdFromMetadataServer(
) → Future< String> - Returns a Future that completes with the Project ID for the current Google Cloud Project by checking project metadata.
-
serveHandler(
Handler handler) → Future< void> -
Serves
handler
on InternetAddress.anyIPv4 using the port returned by listenPort. -
waitForTerminate(
) → Future< void> - Returns a Future that completes when the process receives a ProcessSignal requesting a shutdown.
Exceptions / Errors
- BadConfigurationException
- Thrown if a service is configured incorrectly.
- BadRequestException
-
When thrown in a
Handler
, configured with badRequestMiddleware or similar, causes a response with statusCode to be returned.