gateway

module
v0.0.0-...-0b799ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2024 License: MIT

README

Gateway

Tests codecov Go Report MIT License

Minimal API gateway built on top of Fasthttp for proxying requests to @abyan-dev microservices.

To run the app, use:

go run ./cmd/api

The gateway leverages Docker's DNS to proxy requests to corresponding services by their container names. It is also equipped with middlewares for authorization, TLS, and HTTP logger.

Integration

This gateway uses Fiber's Proxy middleware, so all you need to do is catch all routes after your service's domain using a wildcard:

app.All("<url_in_gateway>", func(c *fiber.Ctx) error {
    targetURL := "<target_url>" + c.OriginalURL()[len("<url_in_gateway>"):]
    if err := proxy.Do(c, targetURL); err != nil {
      return err
    }
    c.Response().Header.Del(fiber.HeaderServer)
    return nil
})

Directories

Path Synopsis
cmd
api
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL