mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
74bb559645
* geoip wip * return nil if ip is empty string or if ParseIP returns nil * add ui component to render geolocation if available, address PR feedback * render public ip if available * add changes file, document geoip in deployment guide * update rest-api docs
24 lines
440 B
Go
24 lines
440 B
Go
package publicip
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type key int
|
|
|
|
const ipKey key = 0
|
|
|
|
// NewContext returns a new context carrying the current remote ip.
|
|
func NewContext(ctx context.Context, ip string) context.Context {
|
|
return context.WithValue(ctx, ipKey, ip)
|
|
}
|
|
|
|
// FromContext extracts the remote ip from context if present.
|
|
func FromContext(ctx context.Context) string {
|
|
ip, ok := ctx.Value(ipKey).(string)
|
|
if !ok {
|
|
return ""
|
|
}
|
|
return ip
|
|
}
|