Documentation ¶
Overview ¶
Package api sets up the HTTP server, configures middleware and routes
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestToIP ¶
RequestToIP finds client IP address from an HTTP request. HTTP Request RemoteAddr provides us with the address of the client or last proxy, therefore we apply some logic to provide more reliable results
- First we try to get IP from the 'X-Forwarded-For' header
- If the header is set, then we get the first IP in this list: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
- If the header is not set - fall back to RemoteAddr
Potential improvements depending on requirements are:
- Add configuration to ignore provided ip ranges
- Add configuration to ignore 'X-Forwarded-For' header (probably we dont want to trust 'X-Forwarded-For' from public internet)
Types ¶
type Middleware ¶
type Middleware struct { DB *db.DBConnection Log *logr.Logger }
Middleware object contains configuration for the RequestMiddleware
func (*Middleware) RequestMiddleware ¶
func (a *Middleware) RequestMiddleware(next http.Handler) http.Handler
RequestMiddleware assigns a unique ID to each request and verifies that IP address is not blacklisted.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server stores HTTP server configuration
Click to show internal directories.
Click to hide internal directories.