51Degrees IP Intelligence Go  4.4

IP Intelligence services for 51Degrees Pipeline

examples/onpremise/reload_from_file.go

Reload from file example of using 51Degrees IP intelligence.

This example illustrates how to use a single reference to the resource manager to use 51Degrees on-premise IP intelligence and invoke the reload functionality instead of maintaining a reference to the dataset directly.

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)


SetConcurrency set concurrency to available CPU size

config.SetConcurrency(uint16(runtime.NumCPU()))


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),
// File System Watcher is by default enabled
ipi_onpremise.WithFileWatch(true),
)


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),


WithFileWatch enables or disables file watching in case 3rd party updates the data file

ipi_onpremise.WithFileWatch(true),


Expected output:

2025/06/23 11:46:08 Reloaded '2' times.
2025/06/23 11:46:08 Failed to reload '0' times.
2025/06/23 11:46:08 Hashcode '850133199' for iteration '0'.
2025/06/23 11:46:08 Hashcode '850133199' for iteration '1'.
2025/06/23 11:46:08 Hashcode '850133199' for iteration '2'.
2025/06/23 11:46:08 Hashcode '850133199' for iteration '3'.
2025/06/23 11:46:08 Hashcode '850133199' for iteration '4'.