mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	UptimeRobot: improve uptime formatting
This commit is contained in:
		
							parent
							
								
									6908e744e1
								
							
						
					
					
						commit
						dd4899a07c
					
				| @ -7,6 +7,7 @@ import ( | |||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/url" | 	"net/url" | ||||||
|  | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/rivo/tview" | 	"github.com/rivo/tview" | ||||||
| 	"github.com/wtfutil/wtf/view" | 	"github.com/wtfutil/wtf/view" | ||||||
| @ -103,13 +104,28 @@ func (widget *Widget) contentFrom(monitors []Monitor) string { | |||||||
| `, | `, | ||||||
| 			prefix, | 			prefix, | ||||||
| 			monitor.Name, | 			monitor.Name, | ||||||
| 			monitor.Uptime, | 			formatUptimes(monitor.Uptime), | ||||||
| 		) | 		) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return str | 	return str | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func formatUptimes(str string) string { | ||||||
|  | 	splits := strings.Split(str, "-") | ||||||
|  | 	str = "" | ||||||
|  | 	for i, s := range splits { | ||||||
|  | 		if i != 0 { | ||||||
|  | 			str += "|" | ||||||
|  | 		} | ||||||
|  | 		s = s[:5] | ||||||
|  | 		s = strings.TrimRight(s, "0") | ||||||
|  | 		s = strings.TrimRight(s, ".") + "%" | ||||||
|  | 		str += s | ||||||
|  | 	} | ||||||
|  | 	return str | ||||||
|  | } | ||||||
|  | 
 | ||||||
| type Monitor struct { | type Monitor struct { | ||||||
| 	Name string `json:"friendly_name"` | 	Name string `json:"friendly_name"` | ||||||
| 	// Monitor state, see: https://uptimerobot.com/api/#parameters | 	// Monitor state, see: https://uptimerobot.com/api/#parameters | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user