From 976bd332fe2d2fb19384b75b3e641bed9cf7a94a Mon Sep 17 00:00:00 2001 From: johnnyjoy Date: Tue, 24 Jun 2025 21:55:27 +0800 Subject: [PATCH] chore: fix linter --- plugin/webhook/webhook.go | 18 +++++++++--------- proto/api/v1/webhook_service.proto | 1 - proto/gen/api/v1/webhook_service.pb.go | 3 +-- server/router/api/v1/memo_service.go | 2 +- server/router/api/v1/resource_name.go | 1 - 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/plugin/webhook/webhook.go b/plugin/webhook/webhook.go index 28f650f9b..fe59d4b88 100644 --- a/plugin/webhook/webhook.go +++ b/plugin/webhook/webhook.go @@ -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)) } diff --git a/proto/api/v1/webhook_service.proto b/proto/api/v1/webhook_service.proto index e69d46a41..acbee62c1 100644 --- a/proto/api/v1/webhook_service.proto +++ b/proto/api/v1/webhook_service.proto @@ -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"; diff --git a/proto/gen/api/v1/webhook_service.pb.go b/proto/gen/api/v1/webhook_service.pb.go index dfa0730eb..16c386929 100644 --- a/proto/gen/api/v1/webhook_service.pb.go +++ b/proto/gen/api/v1/webhook_service.pb.go @@ -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{ diff --git a/server/router/api/v1/memo_service.go b/server/router/api/v1/memo_service.go index 9bc0a25ce..4d3d9fecd 100644 --- a/server/router/api/v1/memo_service.go +++ b/server/router/api/v1/memo_service.go @@ -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) diff --git a/server/router/api/v1/resource_name.go b/server/router/api/v1/resource_name.go index 98e692b31..8a96dd8b6 100644 --- a/server/router/api/v1/resource_name.go +++ b/server/router/api/v1/resource_name.go @@ -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 {