Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe starts HTTP server.
If AWS_LAMBDA_RUNTIME_API environment value is defined, it wait for new AWS Lambda events and handle it as HTTP requests. The format of the events is compatible with Amazon API Gateway Lambda proxy integration and Application Load Balancers. See AWS documents for details.
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html
If AWS_EXECUTION_ENV environment value is AWS_Lambda_go1.x, it returns an error. If AWS_LAMBDA_RUNTIME_API environment value is NOT defined, it just calls http.ListenAndServe.
The handler is typically nil, in which case the DefaultServeMux is used.
If AWS_LAMBDA_RUNTIME_API environment value is defined, ListenAndServe uses it as the invoke mode. The default is InvokeModeBuffered.
Example ¶
package main import ( "fmt" "io" "net/http" "time" "github.com/shogo82148/ridgenative" ) func main() { http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") fmt.Fprintln(w, "Hello World") }) go ridgenative.ListenAndServe(":8080", nil) time.Sleep(time.Second) // wait for starting the server. resp, err := http.Get("http://localhost:8080/hello") if err != nil { panic(err) } defer resp.Body.Close() b, err := io.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(string(b)) }
Output: Hello World
Types ¶
type InvokeMode ¶ added in v1.4.0
type InvokeMode string
InvokeMode is the mode that determines which API operation Lambda uses.
const ( // InvokeModeBuffered indicates that your function is invoked using the Invoke API operation. // Invocation results are available when the payload is complete. InvokeModeBuffered InvokeMode = "BUFFERED" // InvokeModeResponseStream indicates that your function is invoked using // the InvokeWithResponseStream API operation. // It enables your function to stream payload results as they become available. InvokeModeResponseStream InvokeMode = "RESPONSE_STREAM" )