51Degrees IP Intelligence Go  4.4

IP Intelligence services for 51Degrees Pipeline

examples/onpremise/offline_processing.go

Offline processing example of using 51Degrees IP intelligence.

This example demonstrates one possible use of the 51Degrees on-premise IP intelligence API and data for offline data processing. It also demonstrates that you can reuse the retrieved results for multiple uses and only then release it.

This example is available in full on GitHub.

In detail, the example shows how to

1. Specify config for engine:

This setting specifies the performance profile that will be used when initializing the C library.

config := ipi_interop.NewConfigIpi(ipi_interop.InMemory)


2. Initialization of the engine with the following parameters:

engine, err := ipi_onpremise.New(
// Optimized config provided
ipi_onpremise.WithConfigIpi(config),
// Path to your data file
ipi_onpremise.WithDataFile(params.DataFile),
// Enable automatic updates.
ipi_onpremise.WithAutoUpdate(false),
)


WithConfigIpi allows to configure the Ipi matching algorithm.

ipi_onpremise.WithConfigIpi(config)


WithDataFile sets the path to the local data file, this parameter is required to start the engine

ipi_onpremise.WithDataFile(params.DataFile),


WithAutoUpdate enables or disables auto update

ipi_onpremise.WithAutoUpdate(false),


3. Run evidence processing with parameters

runOfflineProcessing(engine, params)


4. Load evidence one by one from the EvidenceYaml file

file, err := os.OpenFile(evidenceFilePath, os.O_RDONLY, 0444)
if err != nil {
log.Fatalf("Failed to open file \"%s\".\n", evidenceFilePath)
}
defer func() {
if err := file.Close(); err != nil {
log.Fatalf("Failed to close file \"%s\".\n", evidenceFilePath)
}
}()


5. Create a new file for writing processed evidence

outFile, err := os.Create(outputFilePath)
if err != nil {
log.Fatalf("Failed to create file %s.\n", outputFilePath)
}
defer func() {
if err := outFile.Close(); err != nil {
log.Fatalf("Failed to close file \"%s\".\n", outputFilePath)
}
}()


6. Get values by property

value, weight, found := result.GetValueWeightByProperty(property)
if !found {
log.Printf("Not found values for the next property %s for address %s", property, IpAddress)
}