doc: add and improve comments
This commit is contained in:
parent
d83acc77b2
commit
d0b1260f62
12 changed files with 50 additions and 26 deletions
|
@ -6,19 +6,21 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
// ClientCommand represents a command from the client (start/stop).
|
||||
// Represents a command from the client (start/stop)
|
||||
type ClientCommand struct {
|
||||
Command string `json:"command"` // comman send to the server
|
||||
Password string `json:"password"` // pomodoro control password
|
||||
Settings PomodoroConfig `json:"settings"` // pomodoro config
|
||||
Command string `json:"command"` // Command send to the server
|
||||
Password string `json:"password"` // Pomodoro control password
|
||||
Settings PomodoroConfig `json:"settings"` // Pomodoro config
|
||||
}
|
||||
|
||||
// Represents a single client
|
||||
type Client struct {
|
||||
Conn *websocket.Conn
|
||||
Mutex sync.Mutex
|
||||
Conn *websocket.Conn // Websocket connection of the client
|
||||
Mutex sync.Mutex // Mutex used to lock
|
||||
}
|
||||
|
||||
// It automatically locks and unlocks the mutex to ensure that only one goroutine can write at a time.
|
||||
// Sends a message to the websocket.
|
||||
// Automatically locks and unlocks the client mutex, to ensure that only one goroutine can write at a time.
|
||||
func (c *Client) SendMessage(messageType int, data []byte) error {
|
||||
c.Mutex.Lock()
|
||||
defer c.Mutex.Unlock()
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package models
|
||||
|
||||
// Represents the configuration of a pomodoro
|
||||
type PomodoroConfig struct {
|
||||
Work int `json:"work"` // Length of work sessions in seconds
|
||||
ShortBreak int `json:"shortBreak"` // Length of short break in seconds
|
||||
LongBreak int `json:"longBreak"` // Length if ling break in seconds
|
||||
LongBreak int `json:"longBreak"` // Length of long break in seconds
|
||||
Sessions int `json:"sessions"` // Number of total sessions
|
||||
}
|
||||
|
||||
// Represents the server configuration
|
||||
type ServerConfig struct {
|
||||
ListenAddress string `json:"listenAddress"` // Server listen address
|
||||
ListenPort int `json:"listenPort"` // Server listen port
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package models
|
||||
|
||||
// ServerMessage represents the data sent to the client via WebSocket.
|
||||
// Represents the data sent to the client via WebSocket
|
||||
type ServerMessage struct {
|
||||
Mode string `json:"mode"` // "Idle", "Work", "ShortBreak", "LongBreak" or "End"
|
||||
Settings PomodoroConfig `json:"settings"` // The currrent pomodoro settings
|
||||
Session int `json:"session"` // Current session number
|
||||
TimeLeft int `json:"time_left"` // Remaining time in seconds
|
||||
Ongoing bool `json:"ongoing"` // Ongoing pomodoro
|
||||
Ongoing bool `json:"ongoing"` // Pomodoro ongoing
|
||||
Paused bool `json:"paused"` // Is timer paused
|
||||
ProtocolVersion string `json:"version"` // Version of the server
|
||||
ProtocolVersion string `json:"version"` // Version of the protocol
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue