Gateway is a simple iris.Runner. It runs Iris Web Applications through AWS Lambda & API Gateway aka Serverless. This includes the Netlify functions (free and paid) too. Thanks to apex/gateway.
The only requirement is the Go Programming Language.
$ go get github.com/iris-contrib/gateway@master
Simply as:
app := iris.New()
// [...]
runner, configurator := gateway.New(gateway.Options{})
app.Run(runner, configurator)
1. Create an account on netlify.com
2. Link a new website with a repository (GitHub or GitLab, public or private)
3. Add a main.go
in the root of that repository:
// Read and Write JSON only.
package main
func main() {
app := iris.New()
app.OnErrorCode(iris.StatusNotFound, notFound)
app.Get("/", index)
app.Get("/ping", status)
// IMPORTANT:
runner, configurator := gateway.New(gateway.Options{
URLPathParameter: "path",
})
app.Run(runner, configurator)
}
func notFound(ctx iris.Context){
code := ctx.GetStatusCode()
msg := iris.StatusText(code)
if err := ctx.GetErr(); err!=nil{
msg = err.Error(),
}
ctx.JSON(iris.Map{
"Message": msg,
"Code": code,
})
}
func index(ctx iris.Context) {
var req map[string]interface{}
ctx.ReadJSON(req)
ctx.JSON(req)
}
func status(ctx iris.Context) {
ctx.JSON(iris.Map{"Message": "OK"})
}
4. Create or open the netlify.toml
file, edit its contents so they look like the following:
[build]
publish = "public"
command = "make build"
functions = "./functions"
[build.environment]
GO_VERSION = "1.17.2"
GIMME_GO_VERSION = "1.17.2"
GO_IMPORT_PATH = "github.com/your_username/your_repo"
[[redirects]]
from = "/api/*"
to = '/.netlify/functions/my_iris_function/:splat'
status = 200
Makefile
build:
go build -o ./functions/my_iris_function
chmod +x ./functions/my_iris_function
5. Use git push
to deploy to Netlify.
The serverless Iris application of will be reachable through your_site.com/api, e.g. https://example.com/api?path=ping
. Have fun!
This software is licensed under the MIT License.