https://github.com/iris-contrib/gateway
Run Iris powered web applications through AWS Lambda & API Gateway
https://github.com/iris-contrib/gateway
aws-iris go golang iris iris-lambda-function iris-serverless lambda-iris netlify netlify-functions serverless
Last synced: 3 months ago
JSON representation
Run Iris powered web applications through AWS Lambda & API Gateway
- Host: GitHub
- URL: https://github.com/iris-contrib/gateway
- Owner: iris-contrib
- License: mit
- Created: 2020-08-23T14:01:47.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-05T20:41:34.000Z (about 2 years ago)
- Last Synced: 2024-11-20T15:50:52.870Z (about 1 year ago)
- Topics: aws-iris, go, golang, iris, iris-lambda-function, iris-serverless, lambda-iris, netlify, netlify-functions, serverless
- Language: Go
- Homepage:
- Size: 86.9 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Gateway
[](https://github.com/iris-contrib/gateway/actions) [](https://goreportcard.com/report/github.com/iris-contrib/gateway) [](https://pkg.go.dev/github.com/iris-contrib/gateway)
Gateway is a simple [iris.Runner](https://github.com/kataras/iris/blob/master/iris.go#L662). It runs Iris Web Applications through AWS Lambda & API Gateway aka **Serverless**. This includes the [Netlify functions (free and paid)](https://docs.netlify.com/functions/overview/) too. Thanks to [apex/gateway](https://github.com/apex/gateway).
## Installation
The only requirement is the [Go Programming Language](https://golang.org/dl).
```sh
$ go get github.com/iris-contrib/gateway@master
```
## Getting Started
Simply as:
```go
app := iris.New()
// [...]
runner, configurator := gateway.New(gateway.Options{})
app.Run(runner, configurator)
```
### Netlify
*1.* Create an account on [netlify.com](https://app.netlify.com/signup)
*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:
```go
// 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:
```tml
[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**
```sh
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!
## License
This software is licensed under the [MIT License](LICENSE).