ProgressBar
Barra de progresso server-side com controle total via Go.
▼
go
bar := components.ProgressBar()
bar.SetTotal(100)
for i := 1; i <= 25; i++ {
bar.Add() // default +1
}
25 / 10025%
▼
go
var mu sync.Mutex
running := false
bar := components.ProgressBar(components.ProgressDefault, components.Stream{})
bar.SetTotal(100)
btnID := components.AutoID()
msgID := components.AutoID()
components.RegisterAction(btnID, func(r *http.Request) string {
mu.Lock()
if running {
mu.Unlock()
return "running"
}
running = true
bar.Current = 0
mu.Unlock()
go func() {
for i := 1; i <= bar.Total; i++ {
bar.Add()
time.Sleep(25 * time.Millisecond)
}
bar.SetVariant(components.ProgressSuccess)
components.SSEBroadcastEvent(bar.GetID(), "done", `{"done":true}`)
mu.Lock()
running = false
mu.Unlock()
}()
return "started"
// frontend faz polling via goui.action a cada 50ms
// e atualiza o DOM com bar.Current / bar.Total
0 / 1000%
✓ Concluído! Reiniciando em 2s...
▼
go
components.ProgressBar() // Default — 25%
components.ProgressBar(components.ProgressSuccess) // Success — 60%
components.ProgressBar(components.ProgressWarning) // Warning — 80%
components.ProgressBar(components.ProgressError) // Error — 100%
components.ProgressBar(components.ProgressInfo, false) // Info, sem label
25 / 10025%
60 / 10060%
160 / 20080%
10 / 10100%
Construtor
| Argumento | Tipo | Descrição |
|---|---|---|
| ProgressVariant | ProgressDefault / Success / Error / Warning / Info | Cor da barra. Default usa a cor primária do tema. |
| bool | bool | Exibir label com current/total e %. Default: true. |
| Class / Style / Attr | — | Customização visual do container. |
Métodos
| Método | Assinatura | Descrição |
|---|---|---|
| SetTotal | SetTotal(n int) *ProgressBarComponent | Define o valor máximo. |
| Add | Add(n ...int) *ProgressBarComponent | Incrementa o valor. Sem arg: +1. Valor ≤ 0 causa panic. |
| SetVariant | SetVariant(v ProgressVariant) *ProgressBarComponent | Muda a variante de cor em tempo de execução. Com Stream, propaga ao frontend via SSE imediatamente. |
Validação do Add
▼
go
bar.Add() // OK — +1
bar.Add(5) // OK — +5
bar.Add(0) // PANIC: value must be positive (> 0), got 0
bar.Add(-3) // PANIC: value must be positive (> 0), got -3