More minor cleanups (no functional change) (#198)

* Redundant type conversions

* Remove redudant type declarations. Inline one-line constructors. Remove unnecessary brackets.

* Simplify name - it's used via package name anyway

* Simplify variable initializations

* Change `var x uint = Y` to `x := uint(Y)`

* More shorthand initialization
pull/200/head
Simon Roberts 3 years ago committed by GitHub
parent ff24fb3b69
commit e1aded93e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,7 @@ func HoldingsCmd() *cobra.Command {
var config string
var sortBy string
var sortDesc bool
var format string = "table"
var format = "table"
var humanReadable bool
var filter []string
var cols []string

@ -14,15 +14,15 @@ import (
// ServerCmd ...
func ServerCmd() *cobra.Command {
var port uint = 22
var address string = "0.0.0.0"
var idleTimeout uint = 0
var maxTimeout uint = 0
var maxSessions uint = 0
var executableBinary string = "cointop"
var hostKeyFile string = cssh.DefaultHostKeyFile
var userConfigType string = cssh.UserConfigTypePublicKey
var colorsDir string = os.Getenv("COINTOP_COLORS_DIR")
port := uint(22)
address := "0.0.0.0"
idleTimeout := uint(0)
maxTimeout := uint(0)
maxSessions := uint(0)
executableBinary := "cointop"
hostKeyFile := cssh.DefaultHostKeyFile
userConfigType := cssh.UserConfigTypePublicKey
colorsDir := os.Getenv("COINTOP_COLORS_DIR")
serverCmd := &cobra.Command{
Use: "server",

@ -25,8 +25,7 @@ type ChartView = ui.View
// NewChartView returns a new chart view
func NewChartView() *ChartView {
var view *ChartView = ui.NewView("chart")
return view
return ui.NewView("chart")
}
var chartLock sync.Mutex
@ -50,17 +49,17 @@ func ChartRanges() []string {
// ChartRangesMap returns map of chart range time ranges
func ChartRangesMap() map[string]time.Duration {
return map[string]time.Duration{
"All Time": time.Duration(10 * 365 * 24 * time.Hour),
"YTD": time.Duration(1 * time.Second), // this will be calculated
"1Y": time.Duration(365 * 24 * time.Hour),
"6M": time.Duration(365 / 2 * 24 * time.Hour),
"3M": time.Duration(365 / 4 * 24 * time.Hour),
"1M": time.Duration(365 / 12 * 24 * time.Hour),
"7D": time.Duration(24 * 7 * time.Hour),
"3D": time.Duration(24 * 3 * time.Hour),
"24H": time.Duration(24 * time.Hour),
"6H": time.Duration(6 * time.Hour),
"1H": time.Duration(1 * time.Hour),
"All Time": 10 * 365 * 24 * time.Hour,
"YTD": 1 * time.Second, // this will be calculated
"1Y": 365 * 24 * time.Hour,
"6M": 365 / 2 * 24 * time.Hour,
"3M": 365 / 4 * 24 * time.Hour,
"1M": 365 / 12 * 24 * time.Hour,
"7D": 24 * 7 * time.Hour,
"3D": 24 * 3 * time.Hour,
"24H": 24 * time.Hour,
"6H": 6 * time.Hour,
"1H": 1 * time.Hour,
}
}
@ -119,7 +118,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
rangeseconds := ct.chartRangesMap[ct.State.selectedChartRange]
if ct.State.selectedChartRange == "YTD" {
ytd := time.Now().Unix() - int64(timeutil.BeginningOfYear().Unix())
ytd := time.Now().Unix() - timeutil.BeginningOfYear().Unix()
rangeseconds = time.Duration(ytd) * time.Second
}
@ -216,7 +215,7 @@ func (ct *Cointop) PortfolioChart() error {
selectedChartRange := ct.State.selectedChartRange // cache here
rangeseconds := ct.chartRangesMap[selectedChartRange]
if selectedChartRange == "YTD" {
ytd := time.Now().Unix() - int64(timeutil.BeginningOfYear().Unix())
ytd := time.Now().Unix() - timeutil.BeginningOfYear().Unix()
rangeseconds = time.Duration(ytd) * time.Second
}

@ -182,19 +182,19 @@ var DefaultCurrency = "USD"
var DefaultChartRange = "1Y"
// DefaultMaxChartWidth ...
var DefaultMaxChartWidth int = 175
var DefaultMaxChartWidth = 175
// DefaultChartHeight ...
var DefaultChartHeight int = 10
var DefaultChartHeight = 10
// DefaultSortBy ...
var DefaultSortBy = "rank"
// DefaultPerPage ...
var DefaultPerPage uint = 100
var DefaultPerPage = uint(100)
// DefaultMaxPages ...
var DefaultMaxPages uint = 35
var DefaultMaxPages = uint(35)
// DefaultColorscheme ...
var DefaultColorscheme = "cointop"

@ -227,9 +227,9 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
if !ok || entry.Coin == "" {
continue
}
var amount string = strconv.FormatFloat(entry.Holdings, 'f', -1, 64)
var coinName string = entry.Coin
var tuple []string = []string{coinName, amount}
amount := strconv.FormatFloat(entry.Holdings, 'f', -1, 64)
coinName := entry.Coin
tuple := []string{coinName, amount}
holdingsIfc = append(holdingsIfc, tuple)
}
sort.Slice(holdingsIfc, func(i, j int) bool {

@ -377,7 +377,7 @@ func (ct *Cointop) SetKeybindings() error {
// TODO: use scrolling table
keys := ct.SortedSupportedCurrencyConversions()
for i, k := range keys {
ct.SetKeybindingMod(rune(alphanumericcharacters[i]), gocui.ModNone, ct.Keyfn(ct.SetCurrencyConverstionFn(k)), ct.Views.Menu.Name())
ct.SetKeybindingMod(alphanumericcharacters[i], gocui.ModNone, ct.Keyfn(ct.SetCurrencyConverstionFn(k)), ct.Views.Menu.Name())
}
return nil

@ -19,8 +19,7 @@ type MarketbarView = ui.View
// NewMarketbarView returns a new marketbar view
func NewMarketbarView() *MarketbarView {
var view *MarketbarView = ui.NewView("marketbar")
return view
return ui.NewView("marketbar")
}
// UpdateMarketbar updates the market bar view
@ -54,7 +53,7 @@ func (ct *Cointop) UpdateMarketbar() error {
var percentChange24H float64
for _, p := range ct.GetPortfolioSlice() {
n := ((p.Balance / total) * p.PercentChange24H)
n := (p.Balance / total) * p.PercentChange24H
if math.IsNaN(n) {
continue
}

@ -10,8 +10,7 @@ type MenuView = ui.View
// NewMenuView returns a new menu view
func NewMenuView() *MenuView {
var view *MenuView = ui.NewView("menu")
return view
return ui.NewView("menu")
}
// HideMenu hides the menu view

@ -413,7 +413,7 @@ func (ct *Cointop) GoToGlobalIndex(idx int) error {
l := ct.TableRowsLen()
atpage := idx / l
ct.SetPage(atpage)
rowIndex := (idx % l)
rowIndex := idx % l
ct.HighlightRow(rowIndex)
ct.UpdateTable()
return nil

@ -983,7 +983,7 @@ func (ct *Cointop) PrintHoldings24HChange(options *TablePrintOptions) error {
}
}
n := ((entry.Balance / total) * entry.PercentChange24H)
n := (entry.Balance / total) * entry.PercentChange24H
if math.IsNaN(n) {
continue
}

@ -14,8 +14,7 @@ type SearchFieldView = ui.View
// NewSearchFieldView returns a new search field view
func NewSearchFieldView() *SearchFieldView {
var view *SearchFieldView = ui.NewView("searchfield")
return view
return ui.NewView("searchfield")
}
// InputView is structure for help view
@ -23,8 +22,7 @@ type InputView = ui.View
// NewInputView returns a new help view
func NewInputView() *InputView {
var view *InputView = ui.NewView("input")
return view
return ui.NewView("input")
}
// OpenSearch opens the search field

@ -15,8 +15,7 @@ type StatusbarView = ui.View
// NewStatusbarView returns a new statusbar view
func NewStatusbarView() *StatusbarView {
var view *StatusbarView = ui.NewView("statusbar")
return view
return ui.NewView("statusbar")
}
// UpdateStatusbar updates the statusbar view

@ -14,8 +14,7 @@ type TableView = ui.View
// NewTableView returns a new table view
func NewTableView() *TableView {
var view *TableView = ui.NewView("table")
return view
return ui.NewView("table")
}
const dots = "..."

@ -128,8 +128,7 @@ type TableHeaderView = ui.View
// NewTableHeaderView returns a new table header view
func NewTableHeaderView() *TableHeaderView {
var view *TableHeaderView = ui.NewView("table_header")
return view
return ui.NewView("table_header")
}
// GetActiveTableHeaders returns the list of active table headers

@ -37,10 +37,10 @@ type Service struct {
// NewCoinGecko new service
func NewCoinGecko(config *Config) *Service {
var maxResultsPerPage uint = 250 // absolute max
var maxResults uint = 0
var maxPages uint = 10
var perPage uint = 100
maxResultsPerPage := 250 // absolute max
maxResults := uint(0)
maxPages := uint(10)
perPage := uint(100)
if config.PerPage > 0 {
perPage = config.PerPage
}

@ -45,7 +45,7 @@ func DamerauLevenshteinDistance(s1, s2 string) int {
// min returns the minimum number of passed int slices.
func min(is ...int) int {
min := int(math.MaxInt32)
min := math.MaxInt32
for _, v := range is {
if min > v {
min = v

@ -8,8 +8,8 @@ import (
"github.com/acarl005/stripansi"
)
// AlignLeft align left
func AlignLeft(t string, n int) string {
// Left align left
func Left(t string, n int) string {
s := stripansi.Strip(t)
slen := utf8.RuneCountInString(s)
if slen > n {
@ -19,8 +19,8 @@ func AlignLeft(t string, n int) string {
return fmt.Sprintf("%s%s", t, strings.Repeat(" ", n-slen))
}
// AlignRight align right
func AlignRight(t string, n int) string {
// Right align right
func Right(t string, n int) string {
s := stripansi.Strip(t)
slen := utf8.RuneCountInString(s)
if slen > n {
@ -30,8 +30,8 @@ func AlignRight(t string, n int) string {
return fmt.Sprintf("%s%s", strings.Repeat(" ", n-slen), t)
}
// AlignCenter align center
func AlignCenter(t string, n int) string {
// Center align center
func Center(t string, n int) string {
s := stripansi.Strip(t)
slen := utf8.RuneCountInString(s)
if slen > n {

@ -205,11 +205,11 @@ func (t *Table) Fprint(w io.Writer) {
var s string
switch c.align {
case AlignLeft:
s = align.AlignLeft(c.name+" ", c.width)
s = align.Left(c.name+" ", c.width)
case AlignRight:
s = align.AlignRight(c.name+" ", c.width)
s = align.Right(c.name+" ", c.width)
case AlignCenter:
s = align.AlignCenter(c.name+" ", c.width)
s = align.Center(c.name+" ", c.width)
}
fmt.Fprintf(w, "%s", s)
@ -237,11 +237,11 @@ func (t *Table) Fprint(w io.Writer) {
var s string
switch c.align {
case AlignLeft:
s = align.AlignLeft(v, c.width)
s = align.Left(v, c.width)
case AlignRight:
s = align.AlignRight(v, c.width)
s = align.Right(v, c.width)
case AlignCenter:
s = align.AlignCenter(v, c.width)
s = align.Center(v, c.width)
}
fmt.Fprintf(w, "%s", s)

@ -21,7 +21,7 @@ import (
g.PercentColor = termui.ColorBlue
*/
const ColorUndef Attribute = Attribute(^uint16(0))
const ColorUndef = Attribute(^uint16(0))
type Gauge struct {
Block

Loading…
Cancel
Save