health

package
v0.0.0-...-da9e6da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package health provides a widget which displays the synchronization status of payment methods. So far it only supports BTCPay Server.

Register the health handler in your HTTP router:

router.Handler(http.MethodGet, "/payment-health", health.Server{btcpayStore})

Parse the health template string along with your HTML templates:

t = template.Must(t.Parse(health.TemplateString))

Execute the template:

{{template "health"}}

Index

Constants

View Source
const TemplateString = `
	{{define "health"}}
		<script>
			function updateHealth() {
				var xhr = new XMLHttpRequest();
				xhr.onreadystatechange = function() {
					if(xhr.readyState == 4) {
						let content = "";
						if(xhr.status == 200) {
							let data = JSON.parse(xhr.responseText);
							for(item of data) {
								content = content + ` + backtick + `<span class="badge bg-${item.Synced ? 'success' : 'danger'} my-2">${item.Name}: ${item.Synced ? 'synced' : 'out of sync'}</span> ` + backtick + `;
							}
						} else {
							content = '<span class="badge bg-warning">could not connect</span>';
						}
						document.getElementById("health-widget").innerHTML = content;
					}
				}
				xhr.open("GET", "/payment-health", true); // true for asynchronous
				xhr.send(null);

				setTimeout(function(){
					updateHealth();
				}, 10*1000); // 10 seconds
			}
			document.write('<span id="health-widget"></span>');
			updateHealth();
		</script>
		<noscript>
			<span class="badge bg-secondary">requires JavaScript</span>
		</noscript>
	{{end}}`

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Name   string
	Synced bool
}

type Server

type Server struct {
	BTCPay btcpay.Store
	Rates  *rates.History
}

func (Server) ServeHTTP

func (srv Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL