server

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package server implements the HTTP and WebSocket server for the scale daemon.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

type Broadcaster struct {
	// contains filtered or unexported fields
}

Broadcaster fans out weight readings to all connected clients

func NewBroadcaster

func NewBroadcaster(broadcast <-chan string) *Broadcaster

NewBroadcaster creates a broadcaster for the given channel

func (*Broadcaster) AddClient

func (b *Broadcaster) AddClient(conn *websocket.Conn)

AddClient registers a new WebSocket connection

func (*Broadcaster) ClientCount

func (b *Broadcaster) ClientCount() int

ClientCount returns the number of connected clients

func (*Broadcaster) RemoveClient

func (b *Broadcaster) RemoveClient(conn *websocket.Conn)

RemoveClient unregisters a WebSocket connection

func (*Broadcaster) Start

func (b *Broadcaster) Start(ctx context.Context)

Start begins broadcasting weights to clients (blocking)

type BuildInfo

type BuildInfo struct {
	Env  string `json:"env"`
	Date string `json:"date"`
	Time string `json:"time"`
}

BuildInfo contains build metadata

type ConfigForClient

type ConfigForClient struct {
	Tipo       string `json:"tipo,omitempty"`
	Puerto     string `json:"puerto"`
	Marca      string `json:"marca"`
	ModoPrueba bool   `json:"modoPrueba"`
	Dir        string `json:"dir"`
	Ambiente   string `json:"ambiente"`
}

ConfigForClient is the config subset sent to clients

type ConfigMessage

type ConfigMessage struct {
	Tipo       string `json:"tipo"`
	Puerto     string `json:"puerto"`
	Marca      string `json:"marca"`
	ModoPrueba bool   `json:"modoPrueba"`
	Dir        string `json:"dir,omitempty"`
}

ConfigMessage matches the exact JSON structure from clients CONSTRAINT: All fields must match legacy format exactly

type EnvironmentInfo

type EnvironmentInfo struct {
	Tipo     string          `json:"tipo"`
	Ambiente string          `json:"ambiente"`
	Version  string          `json:"version"`
	Config   ConfigForClient `json:"config"`
}

EnvironmentInfo sent to clients on connection

type HealthResponse

type HealthResponse struct {
	Status string      `json:"status"`
	Scale  ScaleStatus `json:"scale"`
	Build  BuildInfo   `json:"build"`
	Uptime int         `json:"uptime_seconds"`
}

HealthResponse represents service health (excludes weight data per protocol)

type LogConfigMessage

type LogConfigMessage struct {
	Tipo    string `json:"tipo"`
	Verbose bool   `json:"verbose"`
}

LogConfigMessage for verbose toggle

type LogFlushResult

type LogFlushResult struct {
	Tipo  string `json:"tipo"`
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

LogFlushResult returned after flush operation

type LogLinesResponse

type LogLinesResponse struct {
	Tipo  string   `json:"tipo"`
	Lines []string `json:"lines"`
}

LogLinesResponse returns log lines

type LogTailMessage

type LogTailMessage struct {
	Tipo  string `json:"tipo"`
	Lines int    `json:"lines"`
}

LogTailMessage requests last N lines

type ScaleStatus

type ScaleStatus struct {
	Connected bool   `json:"connected"`
	Port      string `json:"port"`
	Brand     string `json:"brand"`
	TestMode  bool   `json:"test_mode"`
}

ScaleStatus represents scale configuration state (no payload data)

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server handles HTTP and WebSocket connections

func NewServer

func NewServer(
	cfg *config.Config,
	env config.Environment,
	broadcaster *Broadcaster,
	logMgr *logging.Manager,
	buildInfo string,
	onConfigChange func(),
	buildDate string,
	buildTime string,
	startTime time.Time,
) *Server

NewServer creates a new server instance

func (*Server) HandleHealth

func (s *Server) HandleHealth(w http.ResponseWriter, _ *http.Request)

HandleHealth returns service health metrics

func (*Server) HandlePing

func (s *Server) HandlePing(w http.ResponseWriter, _ *http.Request)

HandlePing is a lightweight liveness check

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe inicia el servidor HTTP

func (*Server) Shutdown added in v1.3.0

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the HTTP server

Jump to

Keyboard shortcuts

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