Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe starts HTTP server.
If AWS_EXECUTION_ENV 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 NOT defined, it just calls http.ListenAndServe.
The handler is typically nil, in which case the DefaultServeMux is used.
Example ¶
package main import ( "fmt" "io/ioutil" "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 := ioutil.ReadAll(resp.Body) if err != nil { panic(err) } fmt.Println(string(b)) }
Output: Hello World
Types ¶
This section is empty.