Categorygithub.com/aws-serverless-go/httplam
modulepackage
0.1.0
Repository: https://github.com/aws-serverless-go/httplam.git
Documentation: pkg.go.dev

# README

httplam

httplam is a library that bind AWS Lambda, AWS API Gateway to net/http

Install

go get -u github.com/aws-serverless-go/httplam

Examples

net/http

package main

import (
	"github.com/aws-serverless-go/httplam"
	"net/http"
)

func main() {
	m := http.NewServeMux()
	m.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
		writer.Write([]byte("welcome"))
	})
	if httplam.IsLambdaRuntime() {
		httplam.StartLambdaWithAPIGateway(m)
	} else {
		http.ListenAndServe(":3000", m)
	}
}

github.com/julienschmidt/httprouter

package main

import (
	"fmt"
	"github.com/aws-serverless-go/httplam"
	"github.com/julienschmidt/httprouter"
	"log"
	"net/http"
)

func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	fmt.Fprint(w, "Welcome!\n")
}

func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}

func main() {
	router := httprouter.New()
	router.GET("/", Index)
	router.GET("/hello/:name", Hello)

	if httplam.IsLambdaRuntime() {
		httplam.StartLambdaWithAPIGateway(router)
	} else {
		log.Fatal(http.ListenAndServe(":8080", router))
	}
}

github.com/go-chi/chi

package main

import (
	"github.com/aws-serverless-go/httplam"
	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
	"net/http"
)

func main() {
	r := chi.NewRouter()
	r.Use(middleware.Logger)
	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("welcome"))
	})
	if httplam.IsLambdaRuntime() {
		httplam.StartLambdaWithAPIGateway(r)
	} else {
		http.ListenAndServe(":3000", r)
	}
}

License

MIT License

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author