Initial commit.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
var (
|
||||
errDestIsEmpty = errors.New("dest is empty")
|
||||
errFeedValidate = errors.New("feed configuration validation")
|
||||
errNameIsEmpty = errors.New("name is empty")
|
||||
errOutputIsEmpty = errors.New("output is empty")
|
||||
errURLIsEmpty = errors.New("URL is empty")
|
||||
)
|
||||
|
||||
// Feed is a single RSS feed configuration.
|
||||
type Feed struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
Output string `json:"output"`
|
||||
Destination string `json:"dest"`
|
||||
}
|
||||
|
||||
// Validate validates RSS feed configuration.
|
||||
func (f *Feed) Validate() error {
|
||||
if f.Name == "" {
|
||||
return fmt.Errorf("%w: %w", errFeedValidate, errNameIsEmpty)
|
||||
}
|
||||
|
||||
if f.Output == "" {
|
||||
return fmt.Errorf("%w: %w", errFeedValidate, errOutputIsEmpty)
|
||||
}
|
||||
|
||||
if f.Destination == "" {
|
||||
return fmt.Errorf("%w: %w", errFeedValidate, errDestIsEmpty)
|
||||
}
|
||||
|
||||
if f.URL == "" {
|
||||
return fmt.Errorf("%w: %w", errFeedValidate, errURLIsEmpty)
|
||||
}
|
||||
|
||||
if _, err := url.Parse(f.URL); err != nil {
|
||||
return fmt.Errorf("%w: parse feed URL: %w", errFeedValidate, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user