Something went wrong. Try again.
sloproxy
Something went wrong. Try again.
1.2 kB · 42 lines
Go
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243package home
import ( "context" "encoding/json" "fmt" "strings" "time"
"github.com/router-for-me/CLIProxyAPI/v7/internal/homeplugins")
const pluginStatusReportTimeout = 10 * time.Second
// PluginStatusClient defines the interface for pushing plugin status reports.type PluginStatusClient interface { RPushPluginStatus(ctx context.Context, payload []byte) error}
// ReportPluginStatus marshals the given report, sets NodeID and UpdatedAt,// and pushes it to the provided client with a timeout.func ReportPluginStatus(ctx context.Context, client PluginStatusClient, nodeID string, report homeplugins.SyncReport) error { if client == nil { return fmt.Errorf("home plugin status client is unavailable") } nodeID = strings.TrimSpace(nodeID) if nodeID == "" { return fmt.Errorf("home plugin status node id is empty") } report.NodeID = nodeID report.UpdatedAt = time.Now().UTC() raw, errMarshal := json.Marshal(report) if errMarshal != nil { return errMarshal } if ctx == nil { ctx = context.Background() } reportCtx, cancel := context.WithTimeout(ctx, pluginStatusReportTimeout) defer cancel() return client.RPushPluginStatus(reportCtx, raw)}