Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Code Review
This pull request introduces a configurable API key prefix, replacing the hardcoded "ah-" prefix. Changes include updates to the configuration structures, default settings, and the APIKeyService to support a custom prefix during key generation. A review comment suggests improving the prefix handling in GenerateAPIKey to avoid leading or double hyphens when the prefix is empty or already contains a trailing hyphen.
| // Convert to hex and add ah- prefix | ||
| return "ah-" + hex.EncodeToString(bytes), nil | ||
| // Convert to hex and add prefix | ||
| return prefix + "-" + hex.EncodeToString(bytes), nil |
There was a problem hiding this comment.
The current implementation unconditionally adds a hyphen between the prefix and the random hex string. If the prefix is empty, the generated key will start with a leading hyphen (e.g., -<hex>). Additionally, if the configured prefix already ends with a hyphen (e.g., ah-), the resulting key will contain a double hyphen (e.g., ah--<hex>). It is better to handle these cases gracefully.
| return prefix + "-" + hex.EncodeToString(bytes), nil | |
| prefix = strings.TrimSpace(prefix) | |
| if prefix == "" { | |
| return hex.EncodeToString(bytes), nil | |
| } | |
| return strings.TrimSuffix(prefix, "-") + "-" + hex.EncodeToString(bytes), nil |
Uh oh!
There was an error while loading. Please reload this page.