address linter warnings
This commit is contained in:
parent
34cfaae794
commit
5d730b5fec
|
@ -19,7 +19,7 @@ const (
|
||||||
jsonContentType = "application/json"
|
jsonContentType = "application/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Backend client is used to verify license and to send telemetry reports
|
// BackendClient is used to verify license and to send telemetry reports
|
||||||
// for analyses (anonymous usage data statistics and crash reports)
|
// for analyses (anonymous usage data statistics and crash reports)
|
||||||
type BackendClient struct {
|
type BackendClient struct {
|
||||||
client http.Client
|
client http.Client
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AsciiBox represents a component with ascii-style text
|
||||||
type AsciiBox struct {
|
type AsciiBox struct {
|
||||||
*ui.Block
|
*ui.Block
|
||||||
*data.Consumer
|
*data.Consumer
|
||||||
|
|
|
@ -17,17 +17,18 @@ const (
|
||||||
barIndent int = 1
|
barIndent int = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BarChart presents categorical data with rectangular bars
|
||||||
type BarChart struct {
|
type BarChart struct {
|
||||||
*ui.Block
|
*ui.Block
|
||||||
*data.Consumer
|
*data.Consumer
|
||||||
bars []Bar
|
bars []bar
|
||||||
scale int
|
scale int
|
||||||
maxValue float64
|
maxValue float64
|
||||||
count int64
|
count int64
|
||||||
palette console.Palette
|
palette console.Palette
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bar struct {
|
type bar struct {
|
||||||
label string
|
label string
|
||||||
color ui.Color
|
color ui.Color
|
||||||
value float64
|
value float64
|
||||||
|
@ -39,14 +40,14 @@ func NewBarChart(c config.BarChartConfig, palette console.Palette) *BarChart {
|
||||||
chart := BarChart{
|
chart := BarChart{
|
||||||
Block: component.NewBlock(c.Title, true, palette),
|
Block: component.NewBlock(c.Title, true, palette),
|
||||||
Consumer: data.NewConsumer(),
|
Consumer: data.NewConsumer(),
|
||||||
bars: []Bar{},
|
bars: []bar{},
|
||||||
scale: *c.Scale,
|
scale: *c.Scale,
|
||||||
maxValue: -math.MaxFloat64,
|
maxValue: -math.MaxFloat64,
|
||||||
palette: palette,
|
palette: palette,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, i := range c.Items {
|
for _, i := range c.Items {
|
||||||
chart.AddBar(*i.Label, *i.Color)
|
chart.addBar(*i.Label, *i.Color)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -68,13 +69,14 @@ func (b *BarChart) consumeSample(sample *data.Sample) {
|
||||||
b.count++
|
b.count++
|
||||||
|
|
||||||
float, err := util.ParseFloat(sample.Value)
|
float, err := util.ParseFloat(sample.Value)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.HandleConsumeFailure("Failed to parse a number", err, sample)
|
b.HandleConsumeFailure("Failed to parse a number", err, sample)
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
b.HandleConsumeSuccess()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.HandleConsumeSuccess()
|
||||||
|
|
||||||
index := -1
|
index := -1
|
||||||
for i, bar := range b.bars {
|
for i, bar := range b.bars {
|
||||||
if bar.label == sample.Label {
|
if bar.label == sample.Label {
|
||||||
|
@ -97,8 +99,8 @@ func (b *BarChart) consumeSample(sample *data.Sample) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BarChart) AddBar(label string, color ui.Color) {
|
func (b *BarChart) addBar(label string, color ui.Color) {
|
||||||
b.bars = append(b.bars, Bar{label: label, color: color, value: 0})
|
b.bars = append(b.bars, bar{label: label, color: color, value: 0})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BarChart) reselectMaxValue() {
|
func (b *BarChart) reselectMaxValue() {
|
||||||
|
@ -111,6 +113,7 @@ func (b *BarChart) reselectMaxValue() {
|
||||||
b.maxValue = maxValue
|
b.maxValue = maxValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw renders the barchart
|
||||||
func (b *BarChart) Draw(buffer *ui.Buffer) {
|
func (b *BarChart) Draw(buffer *ui.Buffer) {
|
||||||
b.Block.Draw(buffer)
|
b.Block.Draw(buffer)
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ const (
|
||||||
CurValueLabel = "cur"
|
CurValueLabel = "cur"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Gauge displays cur value between specified min and max values
|
||||||
type Gauge struct {
|
type Gauge struct {
|
||||||
*ui.Block
|
*ui.Block
|
||||||
*data.Consumer
|
*data.Consumer
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Layout represents component arrangement on the screen
|
||||||
type Layout struct {
|
type Layout struct {
|
||||||
ui.Block
|
ui.Block
|
||||||
Components []*component.Component
|
Components []*component.Component
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
const defaultValueLength = 4
|
const defaultValueLength = 4
|
||||||
|
|
||||||
type ChartGrid struct {
|
type chartGrid struct {
|
||||||
timeRange TimeRange
|
timeRange TimeRange
|
||||||
timePerPoint time.Duration
|
timePerPoint time.Duration
|
||||||
valueExtrema ValueExtrema
|
valueExtrema ValueExtrema
|
||||||
|
@ -19,12 +19,12 @@ type ChartGrid struct {
|
||||||
minTimeWidth int
|
minTimeWidth int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RunChart) newChartGrid() ChartGrid {
|
func (c *RunChart) newChartGrid() chartGrid {
|
||||||
|
|
||||||
linesCount := (c.Inner.Max.X - c.Inner.Min.X - c.grid.minTimeWidth) / xAxisGridWidth
|
linesCount := (c.Inner.Max.X - c.Inner.Min.X - c.grid.minTimeWidth) / xAxisGridWidth
|
||||||
timeRange := c.getTimeRange(linesCount)
|
timeRange := c.getTimeRange(linesCount)
|
||||||
|
|
||||||
return ChartGrid{
|
return chartGrid{
|
||||||
timeRange: timeRange,
|
timeRange: timeRange,
|
||||||
timePerPoint: c.timescale / time.Duration(xAxisGridWidth),
|
timePerPoint: c.timescale / time.Duration(xAxisGridWidth),
|
||||||
valueExtrema: getLocalExtrema(c.lines, timeRange),
|
valueExtrema: getLocalExtrema(c.lines, timeRange),
|
||||||
|
|
|
@ -18,7 +18,7 @@ const (
|
||||||
timeFormat = "15:04:05.000"
|
timeFormat = "15:04:05.000"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Legend struct {
|
type legend struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
Details bool
|
Details bool
|
||||||
}
|
}
|
||||||
|
@ -102,15 +102,13 @@ func getColumnWidth(mode Mode, lines []TimeLine, scale int) int {
|
||||||
func getDiffWithPreviousValue(line TimeLine) float64 {
|
func getDiffWithPreviousValue(line TimeLine) float64 {
|
||||||
if len(line.points) < 2 {
|
if len(line.points) < 2 {
|
||||||
return 0
|
return 0
|
||||||
} else {
|
|
||||||
return line.points[len(line.points)-1].value - line.points[len(line.points)-2].value
|
|
||||||
}
|
}
|
||||||
|
return line.points[len(line.points)-1].value - line.points[len(line.points)-2].value
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCurrentValue(line TimeLine) float64 {
|
func getCurrentValue(line TimeLine) float64 {
|
||||||
if len(line.points) == 0 {
|
if len(line.points) == 0 {
|
||||||
return 0
|
return 0
|
||||||
} else {
|
}
|
||||||
return line.points[len(line.points)-1].value
|
return line.points[len(line.points)-1].value
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -38,17 +38,18 @@ const (
|
||||||
CommandMoveSelection = "MOVE_SELECTION"
|
CommandMoveSelection = "MOVE_SELECTION"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RunChart displays observed data in a time sequence
|
||||||
type RunChart struct {
|
type RunChart struct {
|
||||||
*ui.Block
|
*ui.Block
|
||||||
*data.Consumer
|
*data.Consumer
|
||||||
lines []TimeLine
|
lines []TimeLine
|
||||||
grid ChartGrid
|
grid chartGrid
|
||||||
timescale time.Duration
|
timescale time.Duration
|
||||||
mutex *sync.Mutex
|
mutex *sync.Mutex
|
||||||
mode Mode
|
mode Mode
|
||||||
selection time.Time
|
selection time.Time
|
||||||
scale int
|
scale int
|
||||||
legend Legend
|
legend legend
|
||||||
palette console.Palette
|
palette console.Palette
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ func NewRunChart(c config.RunChartConfig, palette console.Palette) *RunChart {
|
||||||
mutex: &sync.Mutex{},
|
mutex: &sync.Mutex{},
|
||||||
scale: *c.Scale,
|
scale: *c.Scale,
|
||||||
mode: ModeDefault,
|
mode: ModeDefault,
|
||||||
legend: Legend{Enabled: c.Legend.Enabled, Details: c.Legend.Details},
|
legend: legend{Enabled: c.Legend.Enabled, Details: c.Legend.Details},
|
||||||
palette: palette,
|
palette: palette,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,10 +160,10 @@ func (c *RunChart) consumeSample(sample *data.Sample) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.HandleConsumeFailure("Failed to parse a number", err, sample)
|
c.HandleConsumeFailure("Failed to parse a number", err, sample)
|
||||||
return
|
return
|
||||||
} else {
|
|
||||||
c.HandleConsumeSuccess()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.HandleConsumeSuccess()
|
||||||
|
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
|
|
||||||
index := -1
|
index := -1
|
||||||
|
@ -318,14 +319,14 @@ func (c *RunChart) moveSelection(shift int) {
|
||||||
c.mode = ModePinpoint
|
c.mode = ModePinpoint
|
||||||
c.selection = getMidRangeTime(c.grid.timeRange)
|
c.selection = getMidRangeTime(c.grid.timeRange)
|
||||||
return
|
return
|
||||||
} else {
|
}
|
||||||
|
|
||||||
c.selection = c.selection.Add(c.grid.timePerPoint * time.Duration(shift))
|
c.selection = c.selection.Add(c.grid.timePerPoint * time.Duration(shift))
|
||||||
if c.selection.After(c.grid.timeRange.max) {
|
if c.selection.After(c.grid.timeRange.max) {
|
||||||
c.selection = c.grid.timeRange.max
|
c.selection = c.grid.timeRange.max
|
||||||
} else if c.selection.Before(c.grid.timeRange.min) {
|
} else if c.selection.Before(c.grid.timeRange.min) {
|
||||||
c.selection = c.grid.timeRange.min
|
c.selection = c.grid.timeRange.min
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for i := range c.lines {
|
for i := range c.lines {
|
||||||
c.lines[i].selectionCoordinate = 0
|
c.lines[i].selectionCoordinate = 0
|
||||||
|
@ -352,9 +353,9 @@ func calculateTimescale(rateMs int) time.Duration {
|
||||||
|
|
||||||
if timescale.Seconds() == 0 {
|
if timescale.Seconds() == 0 {
|
||||||
return time.Second
|
return time.Second
|
||||||
} else {
|
|
||||||
return timescale
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return timescale
|
||||||
}
|
}
|
||||||
|
|
||||||
func braillePoint(point image.Point) image.Point {
|
func braillePoint(point image.Point) image.Point {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SparkLine displays general shape of a measurement variation over time
|
||||||
type SparkLine struct {
|
type SparkLine struct {
|
||||||
*ui.Block
|
*ui.Block
|
||||||
*data.Consumer
|
*data.Consumer
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"image"
|
"image"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TextBox represents a component with regular text
|
||||||
type TextBox struct {
|
type TextBox struct {
|
||||||
*ui.Block
|
*ui.Block
|
||||||
*data.Consumer
|
*data.Consumer
|
||||||
|
|
|
@ -2,7 +2,6 @@ package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"math"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetRectLeftSideCenter(rect image.Rectangle) image.Point {
|
func GetRectLeftSideCenter(rect image.Rectangle) image.Point {
|
||||||
|
@ -33,12 +32,6 @@ func GetRectBottomSideCenter(rect image.Rectangle) image.Point {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDistance(p1 image.Point, p2 image.Point) float64 {
|
|
||||||
x := math.Abs(float64(p1.X - p2.X))
|
|
||||||
y := math.Abs(float64(p1.Y - p2.Y))
|
|
||||||
return math.Sqrt(x*x + y*y)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetRectCoordinates(area image.Rectangle, width int, height int) (int, int, int, int) {
|
func GetRectCoordinates(area image.Rectangle, width int, height int) (int, int, int, int) {
|
||||||
x1 := area.Min.X + area.Dx()/2 - width/2
|
x1 := area.Min.X + area.Dx()/2 - width/2
|
||||||
y1 := area.Min.Y + area.Dy()/2 - height
|
y1 := area.Min.Y + area.Dy()/2 - height
|
||||||
|
|
|
@ -189,9 +189,8 @@ func countEmptyCellsBelow(grid [console.RowsCount][console.ColumnsCount]int, row
|
||||||
for r := row; r < console.RowsCount; r++ {
|
for r := row; r < console.RowsCount; r++ {
|
||||||
if grid[r][column] == 1 {
|
if grid[r][column] == 1 {
|
||||||
return count
|
return count
|
||||||
} else {
|
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
|
count++
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,12 @@ func (c *ComponentConfig) GetSize() Size {
|
||||||
func (c *ComponentConfig) GetRectangle() image.Rectangle {
|
func (c *ComponentConfig) GetRectangle() image.Rectangle {
|
||||||
if c.Position == nil || len(c.Position) == 0 {
|
if c.Position == nil || len(c.Position) == 0 {
|
||||||
return image.ZR
|
return image.ZR
|
||||||
} else {
|
|
||||||
return image.Rect(c.Position[0][0], c.Position[0][1], c.Position[0][0]+c.Position[1][0], c.Position[0][1]+c.Position[1][1])
|
|
||||||
}
|
}
|
||||||
|
return image.Rect(
|
||||||
|
c.Position[0][0],
|
||||||
|
c.Position[0][1],
|
||||||
|
c.Position[0][0]+c.Position[1][0],
|
||||||
|
c.Position[0][1]+c.Position[1][1])
|
||||||
}
|
}
|
||||||
|
|
||||||
type TriggerConfig struct {
|
type TriggerConfig struct {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
// Options with cli flags
|
||||||
type Options struct {
|
type Options struct {
|
||||||
ConfigFile *string `short:"c" long:"config" description:"Path to YAML config file"`
|
ConfigFile *string `short:"c" long:"config" description:"Path to YAML config file"`
|
||||||
LicenseKey *string `short:"l" long:"license" description:"License key. Visit www.sampler.dev for details"`
|
LicenseKey *string `short:"l" long:"license" description:"License key. Visit www.sampler.dev for details"`
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BasicInteractiveShell represents non-PTY interactive shell sampling metadata
|
||||||
type BasicInteractiveShell struct {
|
type BasicInteractiveShell struct {
|
||||||
item *Item
|
item *Item
|
||||||
variables []string
|
variables []string
|
||||||
|
@ -93,7 +94,7 @@ func (s *BasicInteractiveShell) execute() (string, error) {
|
||||||
_ = s.cmd.Wait()
|
_ = s.cmd.Wait()
|
||||||
s.item.basicShell = nil // restart session
|
s.item.basicShell = nil // restart session
|
||||||
}
|
}
|
||||||
return "", errors.New(fmt.Sprintf("Failed to execute command: %s", err))
|
return "", fmt.Errorf("failed to execute command: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout := make(chan bool, 1)
|
timeout := make(chan bool, 1)
|
||||||
|
@ -121,9 +122,8 @@ func (s *BasicInteractiveShell) execute() (string, error) {
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
if errorText.Len() > 0 {
|
if errorText.Len() > 0 {
|
||||||
return "", errors.New(errorText.String())
|
return "", errors.New(errorText.String())
|
||||||
} else {
|
}
|
||||||
return s.item.transform(resultText.String())
|
return s.item.transform(resultText.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
//+build !windows
|
||||||
|
|
||||||
package data
|
package data
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/kr/pty"
|
"github.com/kr/pty"
|
||||||
"github.com/lunixbochs/vtclean"
|
"github.com/lunixbochs/vtclean"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PtyInteractiveShell represents PTY interactive shell sampling metadata
|
||||||
type PtyInteractiveShell struct {
|
type PtyInteractiveShell struct {
|
||||||
item *Item
|
item *Item
|
||||||
variables []string
|
variables []string
|
||||||
|
@ -73,7 +75,7 @@ func (s *PtyInteractiveShell) execute() (string, error) {
|
||||||
_ = s.file.Close()
|
_ = s.file.Close()
|
||||||
s.item.ptyShell = nil // restart session
|
s.item.ptyShell = nil // restart session
|
||||||
}
|
}
|
||||||
return "", errors.New(fmt.Sprintf("Failed to execute command: %s", err))
|
return "", fmt.Errorf("failed to execute command: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
softTimeout := make(chan bool, 1)
|
softTimeout := make(chan bool, 1)
|
||||||
|
|
|
@ -74,14 +74,17 @@ func (i *Item) execute(variables []string, script string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) initInteractiveShell(v []string) error {
|
func (i *Item) initInteractiveShell(v []string) error {
|
||||||
|
|
||||||
timeout := time.Duration(i.rateMs) * time.Millisecond * 3 / 4
|
timeout := time.Duration(i.rateMs) * time.Millisecond * 3 / 4
|
||||||
|
|
||||||
if i.pty {
|
if i.pty {
|
||||||
i.ptyShell = &PtyInteractiveShell{item: i, variables: v, timeout: timeout}
|
i.ptyShell = &PtyInteractiveShell{item: i, variables: v, timeout: timeout}
|
||||||
return i.ptyShell.init()
|
return i.ptyShell.init()
|
||||||
} else {
|
|
||||||
i.basicShell = &BasicInteractiveShell{item: i, variables: v, timeout: timeout}
|
|
||||||
return i.basicShell.init()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i.basicShell = &BasicInteractiveShell{item: i, variables: v, timeout: timeout}
|
||||||
|
|
||||||
|
return i.basicShell.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) transform(sample string) (string, error) {
|
func (i *Item) transform(sample string) (string, error) {
|
||||||
|
|
|
@ -23,9 +23,11 @@ const (
|
||||||
const licenseFileName = "license.yml"
|
const licenseFileName = "license.yml"
|
||||||
|
|
||||||
func GetLicense() *License {
|
func GetLicense() *License {
|
||||||
|
|
||||||
if !fileExists(licenseFileName) {
|
if !fileExists(licenseFileName) {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
}
|
||||||
|
|
||||||
file := readStorageFile(getPlatformStoragePath(licenseFileName))
|
file := readStorageFile(getPlatformStoragePath(licenseFileName))
|
||||||
|
|
||||||
license := new(License)
|
license := new(License)
|
||||||
|
@ -37,7 +39,6 @@ func GetLicense() *License {
|
||||||
|
|
||||||
return license
|
return license
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func SaveLicense(license License) {
|
func SaveLicense(license License) {
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Anonymous usage data, which we collect for analyses and improvements
|
// Statistics represents anonymous usage data, which we collect for analyses and improvements
|
||||||
// User can disable it, along with crash reports, using --telemetry flag
|
// User can disable it, along with crash reports, using --telemetry flag
|
||||||
type Statistics struct {
|
type Statistics struct {
|
||||||
Version string
|
Version string
|
||||||
|
@ -22,6 +22,7 @@ type Statistics struct {
|
||||||
|
|
||||||
const statisticsFileName = "statistics.yml"
|
const statisticsFileName = "statistics.yml"
|
||||||
|
|
||||||
|
// PersistStatistics in file
|
||||||
func PersistStatistics(config *config.Config) *Statistics {
|
func PersistStatistics(config *config.Config) *Statistics {
|
||||||
|
|
||||||
statistics := new(Statistics)
|
statistics := new(Statistics)
|
||||||
|
@ -65,7 +66,9 @@ func PersistStatistics(config *config.Config) *Statistics {
|
||||||
return statistics
|
return statistics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetStatistics from file
|
||||||
func GetStatistics(cfg *config.Config) *Statistics {
|
func GetStatistics(cfg *config.Config) *Statistics {
|
||||||
|
|
||||||
if !fileExists(statisticsFileName) {
|
if !fileExists(statisticsFileName) {
|
||||||
return &Statistics{
|
return &Statistics{
|
||||||
Version: console.AppVersion,
|
Version: console.AppVersion,
|
||||||
|
@ -75,16 +78,18 @@ func GetStatistics(cfg *config.Config) *Statistics {
|
||||||
WindowHeight: 0,
|
WindowHeight: 0,
|
||||||
ComponentsCount: countComponentsPerType(cfg),
|
ComponentsCount: countComponentsPerType(cfg),
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
file := readStorageFile(getPlatformStoragePath(statisticsFileName))
|
file := readStorageFile(getPlatformStoragePath(statisticsFileName))
|
||||||
license := new(Statistics)
|
license := new(Statistics)
|
||||||
|
|
||||||
err := yaml.Unmarshal(file, license)
|
err := yaml.Unmarshal(file, license)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to read statistics file: %v", err)
|
log.Fatalf("Failed to read statistics file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return license
|
return license
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func countComponentsPerType(config *config.Config) map[string]int {
|
func countComponentsPerType(config *config.Config) map[string]int {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue