Documentation
¶
Overview ¶
Package serverless is what Cloud Run and Cloud Functions share: running an HTTP container, waiting until it listens, proxying requests to it and the message-to-HTTP mapping of Hub.Deliver.
Index ¶
- Variables
- func CloseIdle()
- func Deliver(addr string, m *core.Message) error
- func Env(h *core.Hub, host, project string) []string
- func FreePort() int
- func Label(host, suffix string) (string, bool)
- func Port(h *core.Hub) string
- func Proxy(w http.ResponseWriter, r *http.Request, addr string)
- func WaitReady(addr string, d time.Duration, alive func() bool) error
- type Instance
- type Logs
Constants ¶
This section is empty.
Variables ¶
var ErrNoDocker = errors.New("no container engine is running (start Docker, Podman, Colima or OrbStack, or set DOCKER_HOST)")
ErrNoDocker is why a container cannot run.
Functions ¶
func CloseIdle ¶
func CloseIdle()
CloseIdle drops the kept-alive connections to containers and processes, which would hold a server open while it shuts down.
func Deliver ¶
Deliver is the mapping of core.Message onto an HTTP endpoint that Cloud Run and Cloud Functions use for Hub.Deliver (Eventarc, Cloud Tasks, ...):
- the request is a POST of Message.Body to addr;
- its path is Message.Subject (default "/"), and may carry a query string;
- each Message.Attributes key becomes a header, set from StringValue (or BinaryValue), so "ce-type" and "content-type" make a CloudEvent in binary mode; without content-type the body is application/json when it is JSON and text/plain otherwise;
- a non-2xx response, or none, is an error.
func Env ¶
Env is the environment that points Google client libraries in a container (or process) on host at pogi.
Types ¶
type Instance ¶
type Instance struct {
Addr string // host:port that pogi reaches it at
ID string
// contains filtered or unexported fields
}
Instance is a running container.
func Start ¶
func Start(ctx context.Context, h *core.Hub, want int, build func(port int) *docker.Container, logs *Logs, wait time.Duration) (*Instance, error)
Start runs the container build makes and waits until it listens. want is the port it serves in a bridge network; on an engine without a VM (Linux) the container shares the host's network and serves on a free port instead, so build is called with the port to use. Its output goes to logs.
type Logs ¶
type Logs struct {
// contains filtered or unexported fields
}
Logs keeps the last lines a container or process wrote.
func (*Logs) ToLogging ¶
func (l *Logs) ToLogging(h *core.Hub, project, logID, resourceType string, labels map[string]string)
ToLogging also writes every line to Cloud Logging, when it is enabled, as an entry of the log logID (URL-encoded, e.g. "run.googleapis.com%2Fstdout") of a monitored resource.