gofmt: main.go
This commit is contained in:
parent
223a10bf9b
commit
21580b0f53
1 changed files with 34 additions and 34 deletions
68
main.go
68
main.go
|
@ -1,33 +1,33 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
address = lipgloss.NewStyle().Bold(true)
|
address = lipgloss.NewStyle().Bold(true)
|
||||||
crossMark = lipgloss.NewStyle().Foreground(lipgloss.Color("210")).SetString("✗")
|
crossMark = lipgloss.NewStyle().Foreground(lipgloss.Color("210")).SetString("✗")
|
||||||
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("120")).SetString("✓")
|
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("120")).SetString("✓")
|
||||||
port = lipgloss.NewStyle().Background(lipgloss.Color("236"))
|
port = lipgloss.NewStyle().Background(lipgloss.Color("236"))
|
||||||
items = []string{"443", "80", "2222"}
|
items = []string{"443", "80", "2222"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func initialModel() model {
|
func initialModel() model {
|
||||||
return model{
|
return model{
|
||||||
outputs: make([]int, 0),
|
outputs: make([]int, 0),
|
||||||
err: nil,
|
err: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
outputs []int
|
outputs []int
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -38,7 +38,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Init() tea.Cmd {
|
func (m model) Init() tea.Cmd {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
func (m model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
@ -48,30 +48,30 @@ func (m model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
case "ctrl+c":
|
case "ctrl+c":
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, i := range items {
|
for _, i := range items {
|
||||||
cmd := exec.Command("nc", "-zv", "devraza.giize.com", i, "-w", "1")
|
cmd := exec.Command("nc", "-zv", "devraza.giize.com", i, "-w", "1")
|
||||||
out, _ := cmd.CombinedOutput()
|
out, _ := cmd.CombinedOutput()
|
||||||
|
|
||||||
if len(strings.Split(string(out), " ")) == 8 {
|
if len(strings.Split(string(out), " ")) == 8 {
|
||||||
m.outputs = append(m.outputs, 1)
|
m.outputs = append(m.outputs, 1)
|
||||||
} else {
|
} else {
|
||||||
m.outputs = append(m.outputs, 0)
|
m.outputs = append(m.outputs, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m model) View() string {
|
func (m model) View() string {
|
||||||
var combined string
|
var combined string
|
||||||
for idx, i := range m.outputs {
|
for idx, i := range m.outputs {
|
||||||
if i == 1 {
|
if i == 1 {
|
||||||
combined += fmt.Sprintf("%v %v\n", checkMark.Render(), port.Render(" " + items[idx] + " "))
|
combined += fmt.Sprintf("%v %v\n", checkMark.Render(), port.Render(" "+items[idx]+" "))
|
||||||
} else if i == 0 {
|
} else if i == 0 {
|
||||||
combined += fmt.Sprintf("%v %v\n", crossMark.Render(), port.Render(" " + items[idx] + " "))
|
combined += fmt.Sprintf("%v %v\n", crossMark.Render(), port.Render(" "+items[idx]+" "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.err != nil {
|
if m.err != nil {
|
||||||
return fmt.Sprintf("Error: %v\n", m.err)
|
return fmt.Sprintf("Error: %v\n", m.err)
|
||||||
|
|
Loading…
Reference in a new issue