mirror of
https://github.com/usememos/memos.git
synced 2025-10-08 21:39:23 +08:00
chore: fix linter
This commit is contained in:
parent
d6a75bba4c
commit
976bd332fe
5 changed files with 11 additions and 14 deletions
|
@ -20,7 +20,7 @@ var (
|
|||
|
||||
type WebhookRequestPayload struct {
|
||||
// The target URL for the webhook request.
|
||||
Url string `json:"url"`
|
||||
URL string `json:"url"`
|
||||
// The type of activity that triggered this webhook.
|
||||
ActivityType string `json:"activityType"`
|
||||
// The resource name of the creator. Format: users/{user}
|
||||
|
@ -33,12 +33,12 @@ type WebhookRequestPayload struct {
|
|||
func Post(requestPayload *WebhookRequestPayload) error {
|
||||
body, err := json.Marshal(requestPayload)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to marshal webhook request to %s", requestPayload.Url)
|
||||
return errors.Wrapf(err, "failed to marshal webhook request to %s", requestPayload.URL)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", requestPayload.Url, bytes.NewBuffer(body))
|
||||
req, err := http.NewRequest("POST", requestPayload.URL, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to construct webhook request to %s", requestPayload.Url)
|
||||
return errors.Wrapf(err, "failed to construct webhook request to %s", requestPayload.URL)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
@ -47,17 +47,17 @@ func Post(requestPayload *WebhookRequestPayload) error {
|
|||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to post webhook to %s", requestPayload.Url)
|
||||
return errors.Wrapf(err, "failed to post webhook to %s", requestPayload.URL)
|
||||
}
|
||||
|
||||
b, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to read webhook response from %s", requestPayload.Url)
|
||||
return errors.Wrapf(err, "failed to read webhook response from %s", requestPayload.URL)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
return errors.Errorf("failed to post webhook %s, status code: %d, response body: %s", requestPayload.Url, resp.StatusCode, b)
|
||||
return errors.Errorf("failed to post webhook %s, status code: %d, response body: %s", requestPayload.URL, resp.StatusCode, b)
|
||||
}
|
||||
|
||||
response := &struct {
|
||||
|
@ -65,7 +65,7 @@ func Post(requestPayload *WebhookRequestPayload) error {
|
|||
Message string `json:"message"`
|
||||
}{}
|
||||
if err := json.Unmarshal(b, response); err != nil {
|
||||
return errors.Wrapf(err, "failed to unmarshal webhook response from %s", requestPayload.Url)
|
||||
return errors.Wrapf(err, "failed to unmarshal webhook response from %s", requestPayload.URL)
|
||||
}
|
||||
|
||||
if response.Code != 0 {
|
||||
|
@ -82,7 +82,7 @@ func PostAsync(requestPayload *WebhookRequestPayload) {
|
|||
if err := Post(requestPayload); err != nil {
|
||||
// Since we're in a goroutine, we can only log the error
|
||||
slog.Warn("Failed to dispatch webhook asynchronously",
|
||||
slog.String("url", requestPayload.Url),
|
||||
slog.String("url", requestPayload.URL),
|
||||
slog.String("activityType", requestPayload.ActivityType),
|
||||
slog.Any("err", err))
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ syntax = "proto3";
|
|||
|
||||
package memos.api.v1;
|
||||
|
||||
import "api/v1/memo_service.proto";
|
||||
import "google/api/annotations.proto";
|
||||
import "google/api/client.proto";
|
||||
import "google/api/field_behavior.proto";
|
||||
|
|
|
@ -393,7 +393,7 @@ var File_api_v1_webhook_service_proto protoreflect.FileDescriptor
|
|||
|
||||
const file_api_v1_webhook_service_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x1capi/v1/webhook_service.proto\x12\fmemos.api.v1\x1a\x19api/v1/memo_service.proto\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/resource.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\"\xb0\x01\n" +
|
||||
"\x1capi/v1/webhook_service.proto\x12\fmemos.api.v1\x1a\x1cgoogle/api/annotations.proto\x1a\x17google/api/client.proto\x1a\x1fgoogle/api/field_behavior.proto\x1a\x19google/api/resource.proto\x1a\x1bgoogle/protobuf/empty.proto\x1a google/protobuf/field_mask.proto\"\xb0\x01\n" +
|
||||
"\aWebhook\x12\x17\n" +
|
||||
"\x04name\x18\x01 \x01(\tB\x03\xe0A\bR\x04name\x12&\n" +
|
||||
"\fdisplay_name\x18\x02 \x01(\tB\x03\xe0A\x02R\vdisplayName\x12\x15\n" +
|
||||
|
@ -477,7 +477,6 @@ func file_api_v1_webhook_service_proto_init() {
|
|||
if File_api_v1_webhook_service_proto != nil {
|
||||
return
|
||||
}
|
||||
file_api_v1_memo_service_proto_init()
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
|
|
|
@ -698,7 +698,7 @@ func (s *APIV1Service) dispatchMemoRelatedWebhook(ctx context.Context, memo *v1p
|
|||
return errors.Wrap(err, "failed to convert memo to webhook payload")
|
||||
}
|
||||
payload.ActivityType = activityType
|
||||
payload.Url = hook.Url
|
||||
payload.URL = hook.Url
|
||||
|
||||
// Use asynchronous webhook dispatch
|
||||
webhook.PostAsync(payload)
|
||||
|
|
|
@ -146,7 +146,6 @@ func ExtractActivityIDFromName(name string) (int32, error) {
|
|||
}
|
||||
|
||||
// ExtractWebhookIDFromName returns the webhook ID from a resource name.
|
||||
// Expected format: users/{user}/webhooks/{webhook}
|
||||
func ExtractWebhookIDFromName(name string) (string, error) {
|
||||
tokens, err := GetNameParentTokens(name, UserNamePrefix, WebhookNamePrefix)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue