Linter fixes

This commit is contained in:
Vyr Cossont 2024-11-30 20:18:56 -08:00
parent b99ea8121c
commit 88dddd529f
4 changed files with 28 additions and 8 deletions

View file

@ -224,18 +224,18 @@ func validateNormalizeCreate(request *apimodel.WebPushSubscriptionCreateRequest)
if request.Subscription.Endpoint == "" {
return errors.New("endpoint is required")
}
endpointUrl, err := url.Parse(request.Subscription.Endpoint)
endpointURL, err := url.Parse(request.Subscription.Endpoint)
if err != nil {
return errors.New("endpoint must be a valid URL")
}
// TODO: (Vyr) remove http option after testing
if endpointUrl.Scheme != "https" && endpointUrl.Scheme != "http" {
if endpointURL.Scheme != "https" && endpointURL.Scheme != "http" {
return errors.New("endpoint must be an https:// URL")
}
if endpointUrl.Host == "" {
if endpointURL.Host == "" {
return errors.New("endpoint URL must have a host")
}
if endpointUrl.Fragment != "" {
if endpointURL.Fragment != "" {
return errors.New("endpoint URL must not have a fragment")
}

View file

@ -1,3 +1,20 @@
// GoToSocial
// Copyright (C) GoToSocial Authors admin@gotosocial.org
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package bundb
import (
@ -153,6 +170,9 @@ func (w *webPushDB) GetWebPushSubscriptionsByAccountID(ctx context.Context, acco
}
return subscriptionIDs, nil
})
if err != nil {
return nil, err
}
if len(subscriptionIDs) == 0 {
return nil, nil
}

View file

@ -238,12 +238,12 @@ func (r *realSender) sendToSubscription(
return nil
}
// gtsHttpClientRoundTripper helps wrap a GtS HTTP client back into a regular HTTP client,
// gtsHTTPClientRoundTripper helps wrap a GtS HTTP client back into a regular HTTP client,
// so that webpush-go can use our IP filters, bad hosts list, and retries.
type gtsHttpClientRoundTripper struct {
type gtsHTTPClientRoundTripper struct {
httpClient *httpclient.Client
}
func (r *gtsHttpClientRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
func (r *gtsHTTPClientRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
return r.httpClient.Do(request)
}

View file

@ -42,7 +42,7 @@ type Sender interface {
func NewSender(httpClient *httpclient.Client, state *state.State) Sender {
return NewRealSender(
&http.Client{
Transport: &gtsHttpClientRoundTripper{
Transport: &gtsHTTPClientRoundTripper{
httpClient: httpClient,
},
// Other fields are already set on the http.Client inside the httpclient.Client.