From a6d7f90b4687c0225aa1fd008cab8ab288304e43 Mon Sep 17 00:00:00 2001 From: "Laisky.Cai" Date: Wed, 17 Jul 2024 05:59:23 +0000 Subject: [PATCH] refactor: Update alert system with rate limiting, options, and goroutine sender - Refactor and rename `alert pusher hook` to `alertMutation` - Introduce `RateLimiter` interface for rate limiting alert sending - Implement extensive configuration options for `Alert` hook - Enhance `Alert` struct functionality --- gorm/fields.go | 1 + log/alert_test.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/gorm/fields.go b/gorm/fields.go index 20b67de..de57592 100644 --- a/gorm/fields.go +++ b/gorm/fields.go @@ -67,6 +67,7 @@ func (j JSON) Value() (driver.Value, error) { if j.IsNull() { return nil, nil } + return string(j), nil } diff --git a/log/alert_test.go b/log/alert_test.go index 1fd15e5..6b25883 100644 --- a/log/alert_test.go +++ b/log/alert_test.go @@ -15,7 +15,7 @@ func TestAlertHook(t *testing.T) { context.Background(), "https://gq.laisky.com/query/", WithAlertType("hello"), - WithAlertToken("rwkpVuAgaBZQBASKndHK"), + WithAlertToken("YOUR_ALERT_TOKEN"), ) require.NoError(t, err) @@ -31,14 +31,15 @@ func TestAlertHook(t *testing.T) { logger.Error("Error", zap.String("yo", "hello"), zap.Bool("bool", true), zap.Error(errors.Errorf("xxx"))) // t.Error() - time.Sleep(5 * time.Second) + // time.Sleep(1 * time.Second) } + func ExampleAlert() { pusher, err := NewAlert( context.Background(), "https://gq.laisky.com/query/", WithAlertType("hello"), - WithAlertToken("rwkpVuAgaBZQBASKndHK"), + WithAlertToken("YOUR_ALERT_TOKEN"), WithAlertHookLevel(zap.InfoLevel), ) if err != nil {