summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatthieu <matthieu.cneude@gmail.com>2020-10-21 07:24:47 +0200
committermatthieu <matthieu.cneude@gmail.com>2020-10-21 07:24:47 +0200
commit8389ed20ba5ae331da763fa3235dd3b5c5d570fe (patch)
tree904ecefd7ebb4e729faf8f04f994f86d5aacf3c8
parentd7683cc842825daa370a5f61aab1c4e0ca327e3a (diff)
First step to give the possibility to send concurrent request or not
(google analytics forbid too many concurrent requests)
-rw-r--r--cmd/devdash.go1
-rw-r--r--go.mod2
-rw-r--r--internal/platform/ga.go6
-rw-r--r--internal/platform/gsc.go9
-rw-r--r--internal/project.go49
5 files changed, 35 insertions, 32 deletions
diff --git a/cmd/devdash.go b/cmd/devdash.go
index 7878c3b..e2568e1 100644
--- a/cmd/devdash.go
+++ b/cmd/devdash.go
@@ -136,7 +136,6 @@ func build(file string, tui *internal.Tui) {
// TODO choice between concurency and non concurency
// renderFuncs := project.CreateNonConcWidgets()
renderFuncs := project.CreateWidgets()
- fmt.Println(renderFuncs)
if !debug {
project.Render(renderFuncs)
}
diff --git a/go.mod b/go.mod
index bc95fb3..8992949 100644
--- a/go.mod
+++ b/go.mod
@@ -49,7 +49,7 @@ require (
github.com/shuheiktgw/go-travis v0.2.4
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c
- github.com/spf13/afero v1.2.2 // indirect
+ github.com/spf13/afero v1.2.2
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
diff --git a/internal/platform/ga.go b/internal/platform/ga.go
index d8b2435..a448ffe 100644
--- a/internal/platform/ga.go
+++ b/internal/platform/ga.go
@@ -98,10 +98,12 @@ type AnalyticValues struct {
func NewAnalyticsClient(keyfile string) (*Analytics, error) {
// TODO generalize file opening by looking in the different possible folders (see trello ticket)
data, err := ioutil.ReadFile(keyfile)
+
if err != nil {
+ var err2 error
home, _ := homedir.Dir()
- data, err = ioutil.ReadFile(home + "/.config/devdash/" + keyfile)
- if err != nil {
+ data, err2 = ioutil.ReadFile(home + "/.config/devdash/" + keyfile)
+ if err2 != nil {
return nil, fmt.Errorf("reading keyfile %q failed: %v", keyfile, err)
}
}
diff --git a/internal/platform/gsc.go b/internal/platform/gsc.go
index e343798..96f8d60 100644
--- a/internal/platform/gsc.go
+++ b/internal/platform/gsc.go
@@ -3,9 +3,11 @@ package platform
import (
"context"
+ "fmt"
"io/ioutil"
"strings"
+ "github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
@@ -32,7 +34,12 @@ type SearchConsoleResponse struct {
func NewSearchConsoleClient(keyfile string) (*SearchConsole, error) {
data, err := ioutil.ReadFile(keyfile)
if err != nil {
- return nil, errors.Errorf("reading keyfile %q failed: %v", keyfile, err)
+ var err2 error
+ home, _ := homedir.Dir()
+ data, err2 = ioutil.ReadFile(home + "/.config/devdash/" + keyfile)
+ if err2 != nil {
+ return nil, fmt.Errorf("reading keyfile %q failed: %v", keyfile, err)
+ }
}
// webmaster tools
diff --git a/internal/project.go b/internal/project.go
index 18a46a1..d31221f 100644
--- a/internal/project.go
+++ b/internal/project.go
@@ -158,9 +158,8 @@ func mapServiceName(serviceID string) (string, error) {
}
// Create all the widgets and populate them with data.
-// Return channels with render functions
+// Return render functions (fetched concurently)
func (p *project) CreateWidgets() [][][]func() error {
- // TODO: use display.box instead of this shortcut
err := p.addTitle(p.tui)
if err != nil {
err = errors.Wrapf(err, "can't add project title %s", p.name)
@@ -192,8 +191,7 @@ func (p *project) CreateWidgets() [][][]func() error {
}(ch)
continue
}
-
- go getChannelRenderers(service, serviceName, w, p.tui, ch)
+ go channelRenderers(service, serviceName, w, p.tui, ch)
}
}
}
@@ -210,29 +208,11 @@ func (p *project) CreateWidgets() [][][]func() error {
}
}
}
-
return funcs
}
-// getConcurentRenderers and fetch information via different ways depending on Widget (API / SSH / ...)
-// A function to display the widget will be send to a channel.
-// One channel per widget to keep the widget order in a slice.
-func getChannelRenderers(s service, name string, w Widget, tui *Tui, c chan<- func() error) {
- if s == nil {
- c <- DisplayError(tui, errors.Errorf("can't use widget %s without service %s.", w.Name, name))
- } else {
- f, err := s.CreateWidgets(w, tui)
- if err != nil {
- c <- DisplayError(tui, errors.Errorf("%s / %s: %s", name, w.Name, err.Error()))
- } else {
- c <- f
- }
- }
- close(c)
-}
-
// Create all the widgets and populate them with data.
-// Return channels with render functions
+// Return render functions
func (p *project) CreateNonConcWidgets() [][][]func() error {
// TODO: use display.box instead of this shortcut
err := p.addTitle(p.tui)
@@ -248,20 +228,18 @@ func (p *project) CreateNonConcWidgets() [][][]func() error {
funcs[ir] = append(funcs[ir], []func() error{})
for _, w := range col {
w = p.addDefaultTheme(w)
-
service, err := p.mapServiceID(w.serviceID())
if err != nil {
funcs[ir][ic] = append(funcs[ir][ic], DisplayError(p.tui, err))
continue
}
-
serviceName, err := mapServiceName(w.serviceID())
if err != nil {
funcs[ir][ic] = append(funcs[ir][ic], DisplayError(p.tui, err))
continue
}
- funcs[ir][ic] = append(funcs[ir][ic], getFuncRenderers(service, serviceName, w, p.tui))
+ funcs[ir][ic] = append(funcs[ir][ic], funcRenderers(service, serviceName, w, p.tui))
}
}
}
@@ -269,7 +247,7 @@ func (p *project) CreateNonConcWidgets() [][][]func() error {
return funcs
}
-func getFuncRenderers(s service, name string, w Widget, tui *Tui) (f func() error) {
+func funcRenderers(s service, name string, w Widget, tui *Tui) (f func() error) {
if s == nil {
f = DisplayError(tui, errors.Errorf(
"Configuration error - you can't use the widget %s without the service %s.",
@@ -286,6 +264,23 @@ func getFuncRenderers(s service, name string, w Widget, tui *Tui) (f func() erro
return f
}
+// getConcurentRenderers and fetch information via different ways depending on Widget (API / SSH / ...)
+// A function to display the widget will be send in a channel.
+// One channel per widget to keep the widget order in a slice.
+func channelRenderers(s service, name string, w Widget, tui *Tui, c chan<- func() error) {
+ if s == nil {
+ c <- DisplayError(tui, errors.Errorf("can't use widget %s without service %s.", w.Name, name))
+ } else {
+ f, err := s.CreateWidgets(w, tui)
+ if err != nil {
+ c <- DisplayError(tui, errors.Errorf("%s / %s: %s", name, w.Name, err.Error()))
+ } else {
+ c <- f
+ }
+ }
+ close(c)
+}
+
func (p *project) Render(funcs [][][]func() error) {
for r, row := range p.widgets {
for c, col := range row {