Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit cb7ee77

Browse files
committed
Refactor API key handling and remove functions.go
Updated CheckLogs to require an API key for all HTTP requests and improved error handling when the API key is missing. The test-key logic in the example now sets the API key via environment variable. Removed the internal implementation file functions.go, consolidating logic elsewhere. Cleaned up go.mod by removing unnecessary dependencies.
1 parent ee237f5 commit cb7ee77

File tree

4 files changed

+14
-695
lines changed

4 files changed

+14
-695
lines changed

CheckLogs.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
const (
1717
Version = "1.0.0"
18-
DefaultURL = "https://checklogs.dev/api/logs"
18+
DefaultURL = "https://api.checklogs.dev"
1919
)
2020

2121
// LogLevel represents the severity level of a log entry
@@ -176,8 +176,13 @@ func (l *Logger) sendLog(ctx context.Context, data LogData) error {
176176
fmt.Printf("[%s] %s: %s\n", data.Timestamp.Format("15:04:05"), data.Level, data.Message)
177177
}
178178

179-
// Skip HTTP request if silent mode or no API key
180-
if l.options.Silent || l.apiKey == "" {
179+
// Skip HTTP request if no API key (obligatoire maintenant)
180+
if l.apiKey == "" {
181+
return &CheckLogsError{Type: "ConfigurationError", Message: "API key is required"}
182+
}
183+
184+
// Skip console-only mode
185+
if l.options.Silent {
181186
return nil
182187
}
183188

examples/basic.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,22 +291,11 @@ func simulerTraitementDonnees() {
291291

292292
// Fonction principale alternative avec arguments
293293
func init() {
294-
// Fonction pour tester avec une clé API spécifique
295-
if len(os.Args) > 1 && os.Args[1] == "test-key" {
296-
if len(os.Args) > 2 {
297-
testKey := os.Args[2]
298-
fmt.Printf("🔑 Test avec la clé API: %s...\n", testKey[:min(len(testKey), 10)])
299-
300-
logger := checklogs.CreateLogger(testKey)
301-
ctx := context.Background()
302-
303-
err := logger.Info(ctx, "Test de connexion avec clé API fournie")
304-
if err != nil {
305-
log.Printf("❌ Erreur de test: %v", err)
306-
} else {
307-
fmt.Println("✅ Test de connexion réussi")
308-
}
309-
}
294+
// Test avec clé API fournie en argument
295+
if len(os.Args) > 1 && os.Args[1] == "test-key" && len(os.Args) > 2 {
296+
testKey := os.Args[2]
297+
os.Setenv("CHECKLOGS_API_KEY", testKey)
298+
fmt.Printf("🔑 Test avec clé API: %s...\n", testKey[:min(len(testKey), 10)])
310299
}
311300
}
312301

0 commit comments

Comments
 (0)