How bytedance/godlp works
Main Components
• Engine (Core SDK Layer): At the center is the Engine that implements the EngineAPI interface. This is realized through several core files (sdk.go, sdkconfig.go, sdkdeidentify.go, sdkdetect.go, sdkmask.go, and sdkinternal.go) which define and wire up the engine’s functions.
• Configuration Module: Illustrate a configuration component that is responsible for reading and managing the YAML config files (“conf.yml” and the code in the conf directory). This component supplies global settings, sensitive data detection rules, and masking rules.
• Data Structures & API Definitions: Represent a module for “dlpheader” (and possibly “errlist” for error handling) where API data types and constants are defined.
• Logging and Utility Components: Include the “log” module for logging functionality and any other utility components that support the engine (like helper functions or internal libraries).
• External Interfaces: Show the APIs that external callers use (the public functions listed in the README like ApplyConfig, Detect, Deidentify, Mask, etc.). This might also include CLI endpoints (as seen in mainrun/mainrun.go) and unit test / benchmarking tools.
Determining Relationships and Data Flows
– For sensitive data detection, it calls the Detector module.
– For de-identification/masking operations, it routes calls to the Mask module.
– It utilizes the Configuration Module to load and apply detection and masking rules.
• Error Handling & Logging: Indicate the role of the Error Handling module (errlist) for reporting issues and reference the Log module for recording processing steps.
Architectural Patterns and Design Principles
• Modular Design: Emphasize that each key function is encapsulated in its own module (configuration, detector, mask, etc.). This not only supports clarity in testing (as evident from “sdk_test.go” and “bench_test.go”) but also flexibility for future extension.
• Separation of Concerns: Clearly separate the responsibilities by showing how the Engine (API layer) does not embed detection/masking logic but delegates those concerns to specialized submodules.
• Extensibility: Highlight that the project facilitates custom behavior (for example, custom masking functions via RegisterMasker). This could be visualized as an extension point in the Mask module.