handler

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxmindPrefix = "Maxmind/" // Folder containing the maxmind files

)

Variables

View Source
var BucketName = "downloader-" + os.Getenv("GCLOUD_PROJECT") // This is the bucket containing maxmind files
View Source
var CurrentGeoDataset *parser.GeoDataset = nil

This is a pointer to a GeoDataset struct containing the absolute latest data for the annotator to search and reply with

View Source
var GeoLite2Regex = regexp.MustCompile(`Maxmind/\d{4}/\d{2}/\d{2}/\d{8}T\d{6}Z-GeoLite2-City-CSV\.zip`)

This is the regex used to filter for which files we want to consider acceptable for using with Geolite2

Functions

func Annotate

func Annotate(w http.ResponseWriter, r *http.Request)

Annotate is a URL handler that looks up IP address and puts metadata out to the response encoded in json format.

func BatchAnnotate

func BatchAnnotate(w http.ResponseWriter, r *http.Request)

BatchAnnotate is a URL handler that expects the body of the request to contain a JSON encoded slice of annotation.RequestDatas. It will look up all the ip addresses and bundle them into a map of metadata structs (with the keys being the ip concatenated with the base 36 encoded timestamp) and send them back, again JSON encoded.

func BatchValidateAndParse

func BatchValidateAndParse(source io.Reader) ([]annotation.RequestData, error)

BatchValidateAndParse will take a reader (likely the body of a request) containing the JSON encoded array of annotation.RequestDatas. It will then validate that json and use it to construct a slice of annotation.RequestDatas, which it will return. If it encounters an error, then it will return nil and that error.

func ConvertIPNodeToGeoData

func ConvertIPNodeToGeoData(ipNode parser.IPNode, locationNodes []parser.LocationNode) *annotation.GeoData

ConvertIPNodeToGeoData takes a parser.IPNode, plus a list of locationNodes. It will then use that data to fill in a GeoData struct and return its pointer.

func DetermineFilenameOfLatestGeolite2File

func DetermineFilenameOfLatestGeolite2File() (string, error)

DetermineFilenameOfLatestGeolite2File will get a list of filenames from GCS and search through them, eventually returing either the latest filename or an error.

func GetMetadataForSingleIP

func GetMetadataForSingleIP(request *annotation.RequestData) *annotation.GeoData

GetMetadataForSingleIP takes a pointer to a annotation.RequestData struct and will use it to fetch the appropriate associated metadata, returning a pointer. It is gaurenteed to return a non-nil pointer, even if it cannot find the appropriate metadata.

func LoadLatestGeolite2File

func LoadLatestGeolite2File() (*parser.GeoDataset, error)

LoadLatestGeolite2File will check GCS for the latest file, download it, process it, and load it into memory so that it can be easily searched, then it will return a pointer to that GeoDataset or an error.

func PopulateLatestData

func PopulateLatestData()

PopulateLatestData will search to the latest Geolite2 files available in GCS and will use them to create a new GeoDataset which it will place into the global scope as the latest version. It will do so safely with use of the currentDataMutex RW mutex. It it encounters an error, it will halt the program.

func SetupHandlers

func SetupHandlers()

A function to set up any handlers that are needed, including url handlers and pubsub handlers

func ValidateAndParse

func ValidateAndParse(r *http.Request) (*annotation.RequestData, error)

ValidateAndParse takes a request and validates the URL parameters, verifying that it has a valid ip address and time. Then, it uses that to construct a RequestData struct and returns the pointer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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