Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove GODEBUG v2 and set UA #78

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ dist/
.LSOverride
._*
github_token
nom
./nom
6 changes: 1 addition & 5 deletions cmd/nom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
)

func run(args []string, opts Options) error {
cfg, err := config.New(opts.ConfigPath, opts.Pager, opts.PreviewFeeds)
cfg, err := config.New(opts.ConfigPath, opts.Pager, opts.PreviewFeeds, version)
if err != nil {
return err
}
Expand Down Expand Up @@ -67,10 +67,6 @@ func run(args []string, opts Options) error {
}

func main() {
// disable http2 client as causing issues with reddit rss feed requests
// https://github.com/guyfedwards/nom/issues/7
os.Setenv("GODEBUG", "http2client=0")

var opts Options

parser := flags.NewParser(&opts, flags.Default)
Expand Down
44 changes: 22 additions & 22 deletions internal/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,25 +161,25 @@ func (c Commands) TUI() error {
return fmt.Errorf("commands List: %w", err)
}

var errorItems []ErrorItem
// if no feeds in store, fetchAllFeeds, which will return previews
if len(c.config.PreviewFeeds) > 0 {
its, errorItems, err = c.fetchAllFeeds()
if err != nil {
return fmt.Errorf("[commands.go] TUI: %w", err)
}
// if no items, fetchAllFeeds and GetAllFeeds
} else if len(its) == 0 {
_, errorItems, err = c.fetchAllFeeds()
if err != nil {
return fmt.Errorf("[commands.go] TUI: %w", err)
}
// refetch for consistent data across calls
its, err = c.GetAllFeeds()
if err != nil {
return fmt.Errorf("[commands.go] TUI: %w", err)
}
}
var errorItems []ErrorItem
// if no feeds in store, fetchAllFeeds, which will return previews
if len(c.config.PreviewFeeds) > 0 {
its, errorItems, err = c.fetchAllFeeds()
if err != nil {
return fmt.Errorf("[commands.go] TUI: %w", err)
}
// if no items, fetchAllFeeds and GetAllFeeds
} else if len(its) == 0 {
_, errorItems, err = c.fetchAllFeeds()
if err != nil {
return fmt.Errorf("[commands.go] TUI: %w", err)
}
// refetch for consistent data across calls
its, err = c.GetAllFeeds()
if err != nil {
return fmt.Errorf("[commands.go] TUI: %w", err)
}
}

items := convertItems(its)

Expand Down Expand Up @@ -257,7 +257,7 @@ func (c Commands) fetchAllFeeds() ([]store.Item, []ErrorItem, error) {
for _, feed := range feeds {
wg.Add(1)

go fetchFeed(ch, &wg, feed)
go fetchFeed(ch, &wg, feed, c.config.Version)
}

go func() {
Expand Down Expand Up @@ -336,10 +336,10 @@ func (c Commands) GetAllFeeds() ([]store.Item, error) {
return items, nil
}

func fetchFeed(ch chan FetchResultError, wg *sync.WaitGroup, feed config.Feed) {
func fetchFeed(ch chan FetchResultError, wg *sync.WaitGroup, feed config.Feed, version string) {
defer wg.Done()

r, err := rss.Fetch(feed)
r, err := rss.Fetch(feed, version)

if err != nil {
ch <- FetchResultError{res: rss.RSS{}, err: err, url: feed.URL}
Expand Down
3 changes: 2 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Config struct {
AutoRead bool `yaml:"autoread,omitempty"`
ShowFavourites bool
Openers []Opener `yaml:"openers,omitempty"`
Version string
}

func (c *Config) ToggleShowRead() {
Expand All @@ -59,7 +60,7 @@ func (c *Config) ToggleShowFavourites() {
c.ShowFavourites = !c.ShowFavourites
}

func New(configPath string, pager string, previewFeeds []string) (Config, error) {
func New(configPath string, pager string, previewFeeds []string, version string) (Config, error) {
var configDir string

if configPath == "" {
Expand Down
18 changes: 9 additions & 9 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,41 @@ func cleanup() {
}

func TestNewDefault(t *testing.T) {
c, _ := New("", "", []string{})
c, _ := New("", "", []string{}, "")
ucd, _ := os.UserConfigDir()

test.Equal(t, fmt.Sprintf("%s/nom/config.yml", ucd), c.configPath, "Wrong defaults set")
test.Equal(t, fmt.Sprintf("%s/nom", ucd), c.ConfigDir, "Wrong default ConfigDir set")
}

func TestConfigCustomPath(t *testing.T) {
c, _ := New("foo/bar.yml", "", []string{})
c, _ := New("foo/bar.yml", "", []string{}, "")

test.Equal(t, "foo/bar.yml", c.configPath, "Config path override not set")
}

func TestConfigDir(t *testing.T) {
c, _ := New("foo/bizzle/bar.yml", "", []string{})
c, _ := New("foo/bizzle/bar.yml", "", []string{}, "")

test.Equal(t, "foo/bizzle", c.ConfigDir, "ConfigDir not correctly parsed")
}

func TestNewOverride(t *testing.T) {
c, _ := New("foobar", "", []string{})
c, _ := New("foobar", "", []string{}, "")

test.Equal(t, "foobar", c.configPath, "Override not respected")
}

func TestPreviewFeedsOverrideFeedsFromConfigFile(t *testing.T) {
c, _ := New(configFixturePath, "", []string{})
c, _ := New(configFixturePath, "", []string{}, "")
c.Load()
feeds := c.GetFeeds()
test.Equal(t, 3, len(feeds), "Incorrect feeds number")
test.Equal(t, "cattle", feeds[0].URL, "First feed in a config must be cattle")
test.Equal(t, "bird", feeds[1].URL, "Second feed in a config must be bird")
test.Equal(t, "dog", feeds[2].URL, "Third feed in a config must be dog")

c, _ = New(configFixturePath, "", []string{"pumpkin", "radish"})
c, _ = New(configFixturePath, "", []string{"pumpkin", "radish"}, "")
c.Load()
feeds = c.GetFeeds()
test.Equal(t, 2, len(feeds), "Incorrect feeds number")
Expand All @@ -64,7 +64,7 @@ func TestPreviewFeedsOverrideFeedsFromConfigFile(t *testing.T) {
}

func TestConfigLoad(t *testing.T) {
c, _ := New(configFixturePath, "", []string{})
c, _ := New(configFixturePath, "", []string{}, "")
err := c.Load()
if err != nil {
t.Fatalf(err.Error())
Expand All @@ -76,7 +76,7 @@ func TestConfigLoad(t *testing.T) {
}

func TestConfigLoadPrecidence(t *testing.T) {
c, _ := New(configFixturePath, "testpager", []string{})
c, _ := New(configFixturePath, "testpager", []string{}, "")

err := c.Load()
if err != nil {
Expand All @@ -89,7 +89,7 @@ func TestConfigLoadPrecidence(t *testing.T) {
}

func TestConfigAddFeed(t *testing.T) {
c, _ := New(configFixtureWritePath, "", []string{})
c, _ := New(configFixtureWritePath, "", []string{}, "")

err := c.Load()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/rss/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type RSS struct {
Channel Channel `xml:"channel"`
}

func Fetch(f config.Feed) (RSS, error) {
func Fetch(f config.Feed, version string) (RSS, error) {
fp := gofeed.NewParser()
fp.UserAgent = fmt.Sprintf("nom/%s", version)

feed, err := fp.ParseURL(f.URL)
if err != nil {
Expand Down
Loading