fix: linter errors

This commit is contained in:
Christian Muehlhaeuser 2022-11-15 17:07:47 +01:00
parent 4d6c05aea4
commit 6a4ea32e42
3 changed files with 16 additions and 8 deletions

View File

@ -5,15 +5,18 @@ import (
"io/ioutil"
)
// Option is a single configuration option.
type Option struct {
Name string
Value interface{}
}
// Config is a configuration file.
type Config struct {
Options []Option
}
// LoadConfig loads a configuration file.
func LoadConfig(filename string) (Config, error) {
config := Config{}
@ -26,14 +29,16 @@ func LoadConfig(filename string) (Config, error) {
return config, err
}
// Save saves the configuration to a file.
func (c Config) Save(filename string) error {
j, err := json.MarshalIndent(c, "", " ")
if err != nil {
return err
}
return ioutil.WriteFile(filename, j, 0644)
return ioutil.WriteFile(filename, j, 0600)
}
// Value returns the value of a configuration option.
func (c Config) Value(name string) interface{} {
for _, v := range c.Options {
if v.Name == name {
@ -44,6 +49,7 @@ func (c Config) Value(name string) interface{} {
return nil
}
// Set sets the value of a configuration option.
func (c *Config) Set(name, value string) {
found := false
var opts []Option

View File

@ -55,7 +55,7 @@ func search(token string) error {
fmt.Println()
}
pb.Current += 1
pb.Current++
pb.LazyPrint()
}

View File

@ -33,6 +33,7 @@ var (
stripper = bluemonday.StrictPolicy()
)
// Sort options.
const (
SortByLikes = iota
SortByBoosts
@ -97,7 +98,7 @@ func gatherStats() error {
return fmt.Errorf("Can't parse toot: %s", err)
}
pb.Current += 1
pb.Current++
pb.LazyPrint()
if maxToots > 0 && len(stats.Toots) >= maxToots {
@ -205,22 +206,22 @@ func parseToot(status *mastodon.Status, stats *stats) error {
return nil
}
type StatSorter struct {
type statSorter struct {
SortKey int
Key []string
Stats []*tootStat
}
func (a StatSorter) Len() int {
func (a statSorter) Len() int {
return len(a.Stats)
}
func (a StatSorter) Swap(i, j int) {
func (a statSorter) Swap(i, j int) {
a.Key[i], a.Key[j] = a.Key[j], a.Key[i]
a.Stats[i], a.Stats[j] = a.Stats[j], a.Stats[i]
}
func (a StatSorter) Less(i, j int) bool {
func (a statSorter) Less(i, j int) bool {
switch a.SortKey {
case SortByReplies:
return a.Stats[i].Replies < a.Stats[j].Replies
@ -281,8 +282,9 @@ func printTable(cols []string, emptyText string, data []kv) {
fmt.Println()
}
//nolint:unparam
func printTootTable(cols []string, emptyText string, toots []string, tootStats []*tootStat, sortKey int) {
sort.Sort(sort.Reverse(StatSorter{sortKey, toots, tootStats}))
sort.Sort(sort.Reverse(statSorter{sortKey, toots, tootStats}))
var ss []kv
for k, v := range toots {