From 97dc7f579e4d1df59e85147da1695e8c69312b14 Mon Sep 17 00:00:00 2001 From: Paperlz <2305927848@qq.com> Date: Sun, 5 Jul 2026 09:45:41 +0800 Subject: [PATCH 1/2] feat: add notification --- casdoorsdk/notification.go | 37 +++++++++++++++++++++++++++++++ casdoorsdk/notification_global.go | 19 ++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 casdoorsdk/notification.go create mode 100644 casdoorsdk/notification_global.go diff --git a/casdoorsdk/notification.go b/casdoorsdk/notification.go new file mode 100644 index 00000000..bf5bdbce --- /dev/null +++ b/casdoorsdk/notification.go @@ -0,0 +1,37 @@ +// Copyright 2026 The Casdoor Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package casdoorsdk + +import "encoding/json" + +type notificationForm struct { + Content string `json:"content"` +} + +func (c *Client) SendNotification(content string) error { + form := notificationForm{ + Content: content, + } + postBytes, err := json.Marshal(form) + if err != nil { + return err + } + + _, err = c.DoPost("send-notification", nil, postBytes, false, false) + if err != nil { + return err + } + return nil +} diff --git a/casdoorsdk/notification_global.go b/casdoorsdk/notification_global.go new file mode 100644 index 00000000..f75e4f0f --- /dev/null +++ b/casdoorsdk/notification_global.go @@ -0,0 +1,19 @@ +// Copyright 2026 The Casdoor Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package casdoorsdk + +func SendNotification(content string) error { + return globalClient.SendNotification(content) +} From 87c5110061801efa103b1b669fa113073346321a Mon Sep 17 00:00:00 2001 From: Paperlz <2305927848@qq.com> Date: Sun, 5 Jul 2026 10:05:55 +0800 Subject: [PATCH 2/2] fix: pass recipient to notification --- casdoorsdk/notification.go | 8 +++++--- casdoorsdk/notification_global.go | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/casdoorsdk/notification.go b/casdoorsdk/notification.go index bf5bdbce..c00c0672 100644 --- a/casdoorsdk/notification.go +++ b/casdoorsdk/notification.go @@ -17,12 +17,14 @@ package casdoorsdk import "encoding/json" type notificationForm struct { - Content string `json:"content"` + Content string `json:"content"` + Recipient string `json:"recipient,omitempty"` } -func (c *Client) SendNotification(content string) error { +func (c *Client) SendNotification(content string, recipient string) error { form := notificationForm{ - Content: content, + Content: content, + Recipient: recipient, } postBytes, err := json.Marshal(form) if err != nil { diff --git a/casdoorsdk/notification_global.go b/casdoorsdk/notification_global.go index f75e4f0f..99ce5994 100644 --- a/casdoorsdk/notification_global.go +++ b/casdoorsdk/notification_global.go @@ -14,6 +14,6 @@ package casdoorsdk -func SendNotification(content string) error { - return globalClient.SendNotification(content) +func SendNotification(content string, recipient string) error { + return globalClient.SendNotification(content, recipient) }