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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
var (
|
||||
address = lipgloss.NewStyle().Bold(true)
|
||||
crossMark = lipgloss.NewStyle().Foreground(lipgloss.Color("210")).SetString("✗")
|
||||
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("120")).SetString("✓")
|
||||
port = lipgloss.NewStyle().Background(lipgloss.Color("236"))
|
||||
items = []string{"443", "80", "2222"}
|
||||
address = lipgloss.NewStyle().Bold(true)
|
||||
crossMark = lipgloss.NewStyle().Foreground(lipgloss.Color("210")).SetString("✗")
|
||||
checkMark = lipgloss.NewStyle().Foreground(lipgloss.Color("120")).SetString("✓")
|
||||
port = lipgloss.NewStyle().Background(lipgloss.Color("236"))
|
||||
items = []string{"443", "80", "2222"}
|
||||
)
|
||||
|
||||
func initialModel() model {
|
||||
return model{
|
||||
outputs: make([]int, 0),
|
||||
err: nil,
|
||||
outputs: make([]int, 0),
|
||||
err: nil,
|
||||
}
|
||||
}
|
||||
|
||||
type model struct {
|
||||
outputs []int
|
||||
err error
|
||||
outputs []int
|
||||
err error
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -38,7 +38,7 @@ func main() {
|
|||
}
|
||||
|
||||
func (m model) Init() tea.Cmd {
|
||||
return nil
|
||||
return nil
|
||||
}
|
||||
|
||||
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":
|
||||
return m, tea.Quit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, i := range items {
|
||||
cmd := exec.Command("nc", "-zv", "devraza.giize.com", i, "-w", "1")
|
||||
out, _ := cmd.CombinedOutput()
|
||||
for _, i := range items {
|
||||
cmd := exec.Command("nc", "-zv", "devraza.giize.com", i, "-w", "1")
|
||||
out, _ := cmd.CombinedOutput()
|
||||
|
||||
if len(strings.Split(string(out), " ")) == 8 {
|
||||
m.outputs = append(m.outputs, 1)
|
||||
} else {
|
||||
m.outputs = append(m.outputs, 0)
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
if len(strings.Split(string(out), " ")) == 8 {
|
||||
m.outputs = append(m.outputs, 1)
|
||||
} else {
|
||||
m.outputs = append(m.outputs, 0)
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m model) View() string {
|
||||
var combined string
|
||||
for idx, i := range m.outputs {
|
||||
if i == 1 {
|
||||
combined += fmt.Sprintf("%v %v\n", checkMark.Render(), port.Render(" " + items[idx] + " "))
|
||||
} else if i == 0 {
|
||||
combined += fmt.Sprintf("%v %v\n", crossMark.Render(), port.Render(" " + items[idx] + " "))
|
||||
}
|
||||
}
|
||||
var combined string
|
||||
for idx, i := range m.outputs {
|
||||
if i == 1 {
|
||||
combined += fmt.Sprintf("%v %v\n", checkMark.Render(), port.Render(" "+items[idx]+" "))
|
||||
} else if i == 0 {
|
||||
combined += fmt.Sprintf("%v %v\n", crossMark.Render(), port.Render(" "+items[idx]+" "))
|
||||
}
|
||||
}
|
||||
|
||||
if m.err != nil {
|
||||
return fmt.Sprintf("Error: %v\n", m.err)
|
||||
|
|
Loading…
Reference in a new issue