fleet/server/contexts/publicip/publicip.go
Benjamin Edwards 74bb559645
Add public ip to hosts & derive geolocation when rendering host (#4652)
* 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
2022-03-21 12:29:52 -04:00

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
}