Run multiple service using Iris
package main
import (
"log"
"net/http"
"time"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/recover"
"golang.org/x/sync/errgroup"
)
var g errgroup.Group
func startApp1() error {
app := iris.New().SetName("app1")
app.Use(recover.New())
app.Get("/", func(ctx iris.Context) {
app.Get("/", func(ctx iris.Context) {
ctx.JSON(iris.Map{
"code": iris.StatusOK,
"message": "Welcome server 1",
})
})
})
app.Build()
return app.Listen(":8080")
}
func startApp2() error {
app := iris.New().SetName("app2")
app.Use(recover.New())
app.Get("/", func(ctx iris.Context) {
ctx.JSON(iris.Map{
"code": iris.StatusOK,
"message": "Welcome server 2",
})
})
return app.Listen(":8081")
}
func main() {
g.Go(startApp1)
g.Go(startApp2)
if err := g.Wait(); err != nil {
log.Fatal(err)
}
}
Manage multiple Iris instances through the apps
package. Read more here.