Documentation
¶
Overview ¶
Package parser provides data parsing functionality. Supports parsing user data from local files and remote APIs, and provides multiple data merging strategies.
Package parser provides data parsing functionality. Supports parsing user data from local files and remote APIs, and provides multiple data merging strategies.
Package parser provides data parsing functionality. Supports parsing user data from local files and remote APIs, and provides multiple data merging strategies.
Index ¶
- func FromFile(rulesFile string) (rules []define.AllowListUser)
- func FromRemoteConfig(ctx context.Context, url, authorizationHeader string) ([]define.AllowListUser, error)
- func GetRules(ctx context.Context, rulesFile, configURL, authorizationHeader, appMode string) (result []define.AllowListUser)
- func InitHTTPClient(timeout, maxIdleConns int, insecureTLS bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromFile ¶
func FromFile(rulesFile string) (rules []define.AllowListUser)
FromFile reads user rules list from local file.
This function reads user data from specified JSON file with the following features: - Automatically handles file not found (returns empty list) - Automatically handles file read errors (logs warning) - Automatically handles JSON parsing errors (logs warning)
Parameters:
- rulesFile: path to rules file, should be a valid JSON file path
Returns:
- []define.AllowListUser: parsed user list, returns empty list if file does not exist or parsing fails
Side effects:
- Records warning and error logs
- If file exists but read fails, records error log
- If JSON parsing fails, records warning log
func FromRemoteConfig ¶
func FromRemoteConfig(ctx context.Context, url, authorizationHeader string) ([]define.AllowListUser, error)
FromRemoteConfig gets user list from remote configuration (supports context)
This function retrieves JSON-format user configuration data from remote URL with the following features: - Context control: supports timeout and cancellation operations - Automatic retry: uses doRequestWithRetry to implement automatic retry mechanism - Authentication support: optional Authorization request header
Parameters:
- ctx: context for request cancellation and timeout control
- url: remote configuration URL address
- authorizationHeader: optional Authorization request header value, not added if empty
Returns:
- []define.AllowListUser: returns parsed user list on success
- error: returns error on failure, possible reasons include: request initialization failure, network error, HTTP status code error, JSON parsing failure
Side effects:
- Records error and warning logs
- Sets request headers (Content-Type, Cache-Control, Authorization)
func GetRules ¶
func GetRules(ctx context.Context, rulesFile, configURL, authorizationHeader, appMode string) (result []define.AllowListUser)
GetRules gets rules according to mode (supports context)
This function is the unified entry point for rule retrieval, selects different data retrieval and merging strategies based on different modes (appMode). Supported modes include:
- DEFAULT/REMOTE_FIRST: remote first, local supplement
- ONLY_REMOTE: only use remote rules
- ONLY_LOCAL: only use local rules
- LOCAL_FIRST: local first, remote supplement
- REMOTE_FIRST_ALLOW_REMOTE_FAILED: remote first, allow continuation when remote fails
- LOCAL_FIRST_ALLOW_REMOTE_FAILED: local first, allow continuation when remote fails
Parameters:
- ctx: context for request cancellation and timeout control
- rulesFile: local rules file path
- configURL: remote configuration URL
- authorizationHeader: Authorization header for remote request
- appMode: application mode, determines data retrieval strategy
Returns:
- []define.AllowListUser: merged user list, arranged in addition order
Side effects:
- Records debug and warning logs
- May perform network requests (depending on mode)
- May read local files (depending on mode)
func InitHTTPClient ¶
InitHTTPClient initializes HTTP client (using configuration)
Types ¶
This section is empty.