awscloud

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2021 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package awscloud contains Wire providers for AWS services.

Example

This is an example of how to bootstrap an HTTP server running on Amazon Web Services (AWS). The code in this function would be placed in main().

package main

import (
	"context"
	"fmt"
	"log"
	"net/http"

	"github.com/google/wire"
	"go.opencensus.io/trace"
	"gocloud.dev/aws/awscloud"
	"gocloud.dev/server"
	"gocloud.dev/server/health"
)

// This is an example of how to bootstrap an HTTP server running on
// Amazon Web Services (AWS). The code in this function would be
// placed in main().
func main() {
	// Connect and authenticate to AWS.
	srv, cleanup, err := setup(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	defer cleanup()

	// Set up the HTTP routes.
	http.HandleFunc("/", greet)

	// Run the server. This behaves much like http.ListenAndServe,
	// including that passing a nil handler will use http.DefaultServeMux.
	log.Fatal(srv.ListenAndServe(":8080"))
}

// setup is a Wire injector function that creates an HTTP server
// configured to send diagnostics to AWS X-Ray. The second return
// value is a clean-up function that can be called to shut down any
// resources created by setup.
//
// The body of this function will be filled in by running Wire. While
// the name of the function does not matter, the signature signals to
// Wire what provider functions to call. See
// https://github.com/google/wire/blob/master/docs/guide.md#injectors
// for more details.
func setup(ctx context.Context) (*server.Server, func(), error) {
	wire.Build(
		// The AWS set includes all the default wiring for AWS, including
		// for *server.Server.
		awscloud.AWS,
		// Providing nil instructs the server to use the default sampling policy.
		wire.Value(trace.Sampler(nil)),
		// Health checks can be added to delay your server reporting healthy
		// to the load balancer before critical dependencies are available.
		wire.Value([]health.Checker(nil)),
	)
	return nil, nil, nil
}

// greet is an ordinary http.HandleFunc.
func greet(w http.ResponseWriter, req *http.Request) {
	fmt.Fprintln(w, "Hello, World!")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

AWS is a Wire provider set that includes all Amazon Web Services interface implementations in the Go CDK and authenticates using the default session.

Services is a Wire provider set that includes the default wiring for all Amazon Web Services interface implementations in the Go CDK but unlike the AWS set, does not include credentials. Individual services may require additional configuration.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL