Skip to content
Snippets Groups Projects
Commit 58362917 authored by Malte Bauch's avatar Malte Bauch
Browse files

fixed linting errors for goSDN-tview

parent a598af0a
No related branches found
No related tags found
3 merge requests!90Develop,!69Resolve "Stream logger-output to goSDN-tview via gRPC",!53V.0.1.0 Codename Threadbare
...@@ -6,11 +6,13 @@ type view interface { ...@@ -6,11 +6,13 @@ type view interface {
GetContent() tview.Primitive GetContent() tview.Primitive
} }
//App is a GUI-Application bases on tview
type App struct { type App struct {
app *tview.Application app *tview.Application
pages *tview.Pages pages *tview.Pages
} }
//NewApp creates a new GUI-Application
func NewApp() *App { func NewApp() *App {
a := &App{ a := &App{
app: tview.NewApplication(), app: tview.NewApplication(),
...@@ -18,33 +20,40 @@ func NewApp() *App { ...@@ -18,33 +20,40 @@ func NewApp() *App {
return a return a
} }
//SetRoot sets the root of the GUI-Application
func (a *App) SetRoot(v view) { func (a *App) SetRoot(v view) {
a.pages = v.GetContent().(*tview.Pages) a.pages = v.GetContent().(*tview.Pages)
a.app.SetRoot(a.pages, true) a.app.SetRoot(a.pages, true)
} }
//SwitchPage switches to the given (as string) tview page
func (a *App) SwitchPage(s string) { func (a *App) SwitchPage(s string) {
if a.pages.HasPage(s) { if a.pages.HasPage(s) {
a.pages.SwitchToPage(s) a.pages.SwitchToPage(s)
} }
} }
//AddPage adds a new view as page that can be switched to
func (a *App) AddPage(name string, p view) { func (a *App) AddPage(name string, p view) {
a.pages.AddPage(name, p.GetContent(), true, false) a.pages.AddPage(name, p.GetContent(), true, false)
} }
//Run starts the GUI-Application
func (a *App) Run() error { func (a *App) Run() error {
return a.app.Run() return a.app.Run()
} }
//Stop stops the GUI-Application
func (a *App) Stop() { func (a *App) Stop() {
a.app.Stop() a.app.Stop()
} }
//Draw calls tview.Draw()
func (a *App) Draw() { func (a *App) Draw() {
a.app.Draw() a.app.Draw()
} }
//SetFocus sets the focus on new tview.Primitive
func (a *App) SetFocus(v tview.Primitive) { func (a *App) SetFocus(v tview.Primitive) {
a.app.SetFocus(v) a.app.SetFocus(v)
} }
...@@ -8,13 +8,6 @@ import ( ...@@ -8,13 +8,6 @@ import (
"time" "time"
) )
type commandType int
const (
GoSDN commandType = iota
Database
)
const ( const (
defaultName = "gosdn-cli" defaultName = "gosdn-cli"
) )
...@@ -22,10 +15,10 @@ const ( ...@@ -22,10 +15,10 @@ const (
type command struct { type command struct {
Name string Name string
Description string Description string
//CommandType commandType Function func(conn *grpc.ClientConn) string
Function func(conn *grpc.ClientConn) string
} }
//CommandList contains the specific goSDN gRPC calls
var CommandList = []command{ var CommandList = []command{
{"hello", "test connection to goSDN controller", goSDNSayHello}, {"hello", "test connection to goSDN controller", goSDNSayHello},
{"shutdown", "request goSDN controller to shutdown", goSDNShutdown}, {"shutdown", "request goSDN controller to shutdown", goSDNShutdown},
...@@ -35,6 +28,7 @@ var CommandList = []command{ ...@@ -35,6 +28,7 @@ var CommandList = []command{
{"tapigetlink", "get list of links", TAPIGetLink}, {"tapigetlink", "get list of links", TAPIGetLink},
} }
//Connect creates a new connection to the gRPC server
func Connect() (*grpc.ClientConn, error) { func Connect() (*grpc.ClientConn, error) {
address := "localhost:55055" address := "localhost:55055"
return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock()) return grpc.Dial(address, grpc.WithInsecure(), grpc.WithTimeout(5*time.Second), grpc.WithBlock())
......
...@@ -5,10 +5,12 @@ import ( ...@@ -5,10 +5,12 @@ import (
"github.com/rivo/tview" "github.com/rivo/tview"
) )
//AddPNDView is an application view to create a new goSDN PND
type AddPNDView struct { type AddPNDView struct {
addPNDView *tview.Form addPNDView *tview.Form
} }
//NewAddPNDView creates a new AddPNDView
func NewAddPNDView(app *app.App) *AddPNDView { func NewAddPNDView(app *app.App) *AddPNDView {
pndv := &AddPNDView{ pndv := &AddPNDView{
addPNDView: tview.NewForm(), addPNDView: tview.NewForm(),
...@@ -34,6 +36,7 @@ func NewAddPNDView(app *app.App) *AddPNDView { ...@@ -34,6 +36,7 @@ func NewAddPNDView(app *app.App) *AddPNDView {
return pndv return pndv
} }
//GetContent returns the tview.Primitive belonging to the AddPNDView
func (pndv *AddPNDView) GetContent() tview.Primitive { func (pndv *AddPNDView) GetContent() tview.Primitive {
return pndv.addPNDView return pndv.addPNDView
} }
...@@ -7,10 +7,12 @@ import ( ...@@ -7,10 +7,12 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
) )
//CommandListView is an application view to display all the goSDN commands
type CommandListView struct { type CommandListView struct {
commandsList *tview.List commandsList *tview.List
} }
//NewCommandListView creates a new CommandListView
func NewCommandListView() *CommandListView { func NewCommandListView() *CommandListView {
cv := &CommandListView{ cv := &CommandListView{
commandsList: tview.NewList(), commandsList: tview.NewList(),
...@@ -22,10 +24,14 @@ func NewCommandListView() *CommandListView { ...@@ -22,10 +24,14 @@ func NewCommandListView() *CommandListView {
return cv return cv
} }
//GetContent returns the tview.Primitive belonging to the CommandListView
func (cv *CommandListView) GetContent() tview.Primitive { func (cv *CommandListView) GetContent() tview.Primitive {
return cv.commandsList return cv.commandsList
} }
//GetCommands gets all goSDN commands from a command list and creates new
//tview.List items for each one of them. The specific gRPC functions are added
//as tview.Selected() function
func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView, func (cv *CommandListView) GetCommands(app *app.App, rv *ResultAndInputView,
conn *grpc.ClientConn) { conn *grpc.ClientConn) {
//TODO: create own command in grpc -> commands //TODO: create own command in grpc -> commands
......
...@@ -6,10 +6,13 @@ import ( ...@@ -6,10 +6,13 @@ import (
"time" "time"
) )
//DatabaseStatusView is an application view to display the current status of
//the database (e.g. connected, disconnected,...)
type DatabaseStatusView struct { type DatabaseStatusView struct {
databaseStatusView *tview.TextView databaseStatusView *tview.TextView
} }
//NewDatabaseStatusView creates a new DatabaseStatusView
func NewDatabaseStatusView(app *app.App) *DatabaseStatusView { func NewDatabaseStatusView(app *app.App) *DatabaseStatusView {
dv := &DatabaseStatusView{ dv := &DatabaseStatusView{
databaseStatusView: tview.NewTextView(), databaseStatusView: tview.NewTextView(),
...@@ -21,21 +24,25 @@ func NewDatabaseStatusView(app *app.App) *DatabaseStatusView { ...@@ -21,21 +24,25 @@ func NewDatabaseStatusView(app *app.App) *DatabaseStatusView {
SetBorder(true). SetBorder(true).
SetTitle("Database") SetTitle("Database")
// run the periodical refresh in a new go routine
go databaseTicker(dv) go databaseTicker(dv)
return dv return dv
} }
//GetContent returns the tview.Primitive belonging to the DatabaseStatusView
func (dv *DatabaseStatusView) GetContent() tview.Primitive { func (dv *DatabaseStatusView) GetContent() tview.Primitive {
return dv.databaseStatusView return dv.databaseStatusView
} }
//SetContent sets new string content for the DatabaseStatusView
func (dv *DatabaseStatusView) SetContent(s string) { func (dv *DatabaseStatusView) SetContent(s string) {
dv.databaseStatusView.Clear() dv.databaseStatusView.Clear()
dv.databaseStatusView.SetText(s) dv.databaseStatusView.SetText(s)
} }
func databaseTicker(dv *DatabaseStatusView) { func databaseTicker(dv *DatabaseStatusView) {
//TODO see gRPCStatusView!
ticker := time.NewTicker(5 * time.Second) ticker := time.NewTicker(5 * time.Second)
for t := range ticker.C { for t := range ticker.C {
dv.SetContent(t.String()) dv.SetContent(t.String())
......
...@@ -6,12 +6,15 @@ import ( ...@@ -6,12 +6,15 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
) )
//FooterView is an application view to display the footer of the application it
//consists multiple other application views
type FooterView struct { type FooterView struct {
footerView *tview.Flex footerView *tview.Flex
databaseStatusView *DatabaseStatusView databaseStatusView *DatabaseStatusView
gRPCStatusView *GRPCStatusView gRPCStatusView *GRPCStatusView
} }
//NewFooterView creates a new FooterView
func NewFooterView(app *app.App, conn *grpc.ClientConn) *FooterView { func NewFooterView(app *app.App, conn *grpc.ClientConn) *FooterView {
fw := &FooterView{ fw := &FooterView{
...@@ -30,6 +33,7 @@ func NewFooterView(app *app.App, conn *grpc.ClientConn) *FooterView { ...@@ -30,6 +33,7 @@ func NewFooterView(app *app.App, conn *grpc.ClientConn) *FooterView {
return fw return fw
} }
//GetContent returns the tview.Primitive belonging to the FooterView
func (fw *FooterView) GetContent() tview.Primitive { func (fw *FooterView) GetContent() tview.Primitive {
return fw.footerView return fw.footerView
} }
...@@ -7,10 +7,13 @@ import ( ...@@ -7,10 +7,13 @@ import (
"time" "time"
) )
//GRPCStatusView is an application view to display the current status of
//the gRPC server (e.g. connected, unavailable,...)
type GRPCStatusView struct { type GRPCStatusView struct {
gRPCStatusView *tview.TextView gRPCStatusView *tview.TextView
} }
//NewGRPCStatusView creates a new GRPCStatusView
func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView { func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView {
sv := &GRPCStatusView{ sv := &GRPCStatusView{
gRPCStatusView: tview.NewTextView(), gRPCStatusView: tview.NewTextView(),
...@@ -23,8 +26,8 @@ func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView { ...@@ -23,8 +26,8 @@ func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView {
SetBorder(true). SetBorder(true).
SetTitle("gRPC") SetTitle("gRPC")
//TODO: maybe there is another way to do this. //TODO: gRPCs Health Check looks like a way better alternative here!
// pretty ugly atm, since it re-draws every 5 seconds... //--> no app.Draw() required anymore
sv.gRPCStatusView.SetChangedFunc(func() { sv.gRPCStatusView.SetChangedFunc(func() {
app.Draw() app.Draw()
}) })
...@@ -34,10 +37,12 @@ func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView { ...@@ -34,10 +37,12 @@ func NewGRPCStatusView(app *app.App, conn *grpc.ClientConn) *GRPCStatusView {
return sv return sv
} }
//GetContent returns the tview.Primitive belonging to the gRPCStatusView
func (sv *GRPCStatusView) GetContent() tview.Primitive { func (sv *GRPCStatusView) GetContent() tview.Primitive {
return sv.gRPCStatusView return sv.gRPCStatusView
} }
//SetContent sets new string content for the gRPCStatusView
func (sv *GRPCStatusView) SetContent(s string) { func (sv *GRPCStatusView) SetContent(s string) {
sv.gRPCStatusView.Clear() sv.gRPCStatusView.Clear()
sv.gRPCStatusView.SetText(s) sv.gRPCStatusView.SetText(s)
......
...@@ -9,11 +9,13 @@ var goSDNAscii = ` ____ ____ _ _ _ _ _ ...@@ -9,11 +9,13 @@ var goSDNAscii = ` ____ ____ _ _ _ _ _
\__ |\___/____/|____/|_| \_| |_| |_|\___/ \___|_| |_|___/\___|_| |_|\__,_|_|\___| |____/ \__,_|_| |_| |_| |_|___/\__\__,_|\__,_|\__| \__ |\___/____/|____/|_| \_| |_| |_|\___/ \___|_| |_|___/\___|_| |_|\__,_|_|\___| |____/ \__,_|_| |_| |_| |_|___/\__\__,_|\__,_|\__|
|___/ ` |___/ `
//HeaderView is an application view to display the header of the application
type HeaderView struct { type HeaderView struct {
headerFlex *tview.Flex headerFlex *tview.Flex
titleView *tview.TextView titleView *tview.TextView
} }
//NewHeaderView creates a new HeaderView
func NewHeaderView() *HeaderView { func NewHeaderView() *HeaderView {
//TODO: change to uses FlexBox if there is more to display in the header //TODO: change to uses FlexBox if there is more to display in the header
hv := &HeaderView{ hv := &HeaderView{
...@@ -27,6 +29,7 @@ func NewHeaderView() *HeaderView { ...@@ -27,6 +29,7 @@ func NewHeaderView() *HeaderView {
return hv return hv
} }
//GetContent returns the tview.Primitive belonging to the HeaderView
func (hv *HeaderView) GetContent() tview.Primitive { func (hv *HeaderView) GetContent() tview.Primitive {
return hv.titleView return hv.titleView
} }
...@@ -6,6 +6,9 @@ import ( ...@@ -6,6 +6,9 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
) )
//MainView is an application view to display the main content of the application.
//It is the entry point for the application and contains all necessary views for
//for that purpose
type MainView struct { type MainView struct {
pages *tview.Pages pages *tview.Pages
mainGrid *tview.Grid mainGrid *tview.Grid
...@@ -15,6 +18,7 @@ type MainView struct { ...@@ -15,6 +18,7 @@ type MainView struct {
footerView *FooterView footerView *FooterView
} }
//NewMainView creates a new MainView
func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
mv := &MainView{ mv := &MainView{
pages: tview.NewPages(), pages: tview.NewPages(),
...@@ -40,6 +44,7 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView { ...@@ -40,6 +44,7 @@ func NewMainView(app *app.App, conn *grpc.ClientConn) *MainView {
return mv return mv
} }
//GetContent returns the tview.Primitive belonging to the MainView
func (mv *MainView) GetContent() tview.Primitive { func (mv *MainView) GetContent() tview.Primitive {
return mv.pages return mv.pages
} }
...@@ -5,12 +5,15 @@ import ( ...@@ -5,12 +5,15 @@ import (
"github.com/rivo/tview" "github.com/rivo/tview"
) )
//ResultAndInputView is an application view to display different other views.
//Depending on the required features the views are changed.
type ResultAndInputView struct { type ResultAndInputView struct {
pages *tview.Pages pages *tview.Pages
resultView *tview.TextView resultView *tview.TextView
pndInputView *AddPNDView pndInputView *AddPNDView
} }
//NewResultAndInputView creates a new ResultAndInputView
func NewResultAndInputView(app *app.App) *ResultAndInputView { func NewResultAndInputView(app *app.App) *ResultAndInputView {
rv := &ResultAndInputView{ rv := &ResultAndInputView{
pages: tview.NewPages(), pages: tview.NewPages(),
...@@ -31,14 +34,18 @@ func NewResultAndInputView(app *app.App) *ResultAndInputView { ...@@ -31,14 +34,18 @@ func NewResultAndInputView(app *app.App) *ResultAndInputView {
return rv return rv
} }
//GetContent returns the tview.Primitive belonging to the ResultAndInputView
func (rv *ResultAndInputView) GetContent() tview.Primitive { func (rv *ResultAndInputView) GetContent() tview.Primitive {
return rv.pages return rv.pages
} }
//ChangeContentView changes the current content (tview.Primitive) that is visible
//inside this view
func (rv *ResultAndInputView) ChangeContentView(s string) { func (rv *ResultAndInputView) ChangeContentView(s string) {
rv.pages.SwitchToPage(s) rv.pages.SwitchToPage(s)
} }
//SetContent sets new string content for the ResultAndInputView
func (rv *ResultAndInputView) SetContent(s string) { func (rv *ResultAndInputView) SetContent(s string) {
rv.resultView.Clear() rv.resultView.Clear()
rv.resultView.SetText(s) rv.resultView.SetText(s)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment