Run multiple service using Iris

  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "time"
  6. "github.com/kataras/iris/v12"
  7. "github.com/kataras/iris/v12/middleware/recover"
  8. "golang.org/x/sync/errgroup"
  9. )
  10. var g errgroup.Group
  11. func startApp1() error {
  12. app := iris.New().SetName("app1")
  13. app.Use(recover.New())
  14. app.Get("/", func(ctx iris.Context) {
  15. app.Get("/", func(ctx iris.Context) {
  16. ctx.JSON(iris.Map{
  17. "code": iris.StatusOK,
  18. "message": "Welcome server 1",
  19. })
  20. })
  21. })
  22. app.Build()
  23. return app.Listen(":8080")
  24. }
  25. func startApp2() error {
  26. app := iris.New().SetName("app2")
  27. app.Use(recover.New())
  28. app.Get("/", func(ctx iris.Context) {
  29. ctx.JSON(iris.Map{
  30. "code": iris.StatusOK,
  31. "message": "Welcome server 2",
  32. })
  33. })
  34. return app.Listen(":8081")
  35. }
  36. func main() {
  37. g.Go(startApp1)
  38. g.Go(startApp2)
  39. if err := g.Wait(); err != nil {
  40. log.Fatal(err)
  41. }
  42. }

Manage multiple Iris instances through the apps package. Read more here.