package ntfy import ( "sync" "time" ) // States of a subscription, as Status reports them. const ( // StateConnecting is a subscription opening its connection. StateConnecting = "connecting" // StateConnected is a subscription reading its stream. StateConnected = "connected" // StateBackoff is a subscription waiting to reconnect after a failure. StateBackoff = "backoff" // StateUnauthorized is a subscription whose credentials the server // refused; it tries again every five minutes. StateUnauthorized = "unauthorized" ) // Status is a snapshot of a subscription, for health checks. It holds no // credentials and nothing a message says. type Status struct { Name string State string // ConnectedSince is when the current connection opened; zero when // there is none. ConnectedSince time.Time // LastMessageAt is when the last message arrived; zero when none has. LastMessageAt time.Time // Printed is how many messages printed on their own card, Digested how // many were held for a digest, and Held how many wait for the next one. Printed int Digested int Held int // LastError says why the last connection failed; "" once one opens. LastError string } // status is a Status shared between the subscription and its readers. type status struct { mu sync.Mutex s Status } func (st *status) get() Status { st.mu.Lock() defer st.mu.Unlock() return st.s } func (st *status) update(fn func(*Status)) { st.mu.Lock() defer st.mu.Unlock() fn(&st.s) }