mirror of
https://github.com/kopia/kopia.git
synced 2026-05-11 00:04:46 -04:00
Remove unused-parameter exclusion for `ctx` in revive linter. --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> Co-authored-by: Matthieu MOREL <matthieu.morel35@gmail.com>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package pushover
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/notification/sender"
|
|
)
|
|
|
|
// Options defines Pushover notification sender options.
|
|
type Options struct {
|
|
AppToken string `json:"appToken"`
|
|
UserKey string `json:"userKey"`
|
|
Format string `json:"format"` // format of the message, must be "html" or "md"
|
|
|
|
Endpoint string `json:"endpoint,omitempty"` // override the default endpoint for testing
|
|
}
|
|
|
|
// ApplyDefaultsAndValidate applies default values and validates the configuration.
|
|
func (o *Options) ApplyDefaultsAndValidate(_ context.Context) error {
|
|
if o.AppToken == "" {
|
|
return errors.Errorf("App Token must be provided")
|
|
}
|
|
|
|
if o.UserKey == "" {
|
|
return errors.Errorf("User Key must be provided")
|
|
}
|
|
|
|
if err := sender.ValidateMessageFormatAndSetDefault(&o.Format, sender.FormatPlainText); err != nil {
|
|
return errors.Wrap(err, "invalid format")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// MergeOptions updates the destination options with the source options.
|
|
func MergeOptions(ctx context.Context, src Options, dst *Options, isUpdate bool) error {
|
|
copyOrMerge(&dst.AppToken, src.AppToken, isUpdate)
|
|
copyOrMerge(&dst.UserKey, src.UserKey, isUpdate)
|
|
|
|
return dst.ApplyDefaultsAndValidate(ctx)
|
|
}
|
|
|
|
func copyOrMerge[T comparable](dst *T, src T, isUpdate bool) {
|
|
var defaultT T
|
|
|
|
if !isUpdate || src != defaultT {
|
|
*dst = src
|
|
}
|
|
}
|