fix: linter errors

pull/25/head
Christian Muehlhaeuser 2022-11-15 17:07:47 +01:00
rodzic 4d6c05aea4
commit 6a4ea32e42
3 zmienionych plików z 16 dodań i 8 usunięć

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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