60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
// Config holds the client configuration
|
|
type Config struct {
|
|
ServerAddress string `json:"server_address"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
// ReadConfig reads the client configuration from a JSON file
|
|
func ReadConfig(filePath string) (*Config, error) {
|
|
file, err := ioutil.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var config Config
|
|
if err := json.Unmarshal(file, &config); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &config, nil
|
|
}
|
|
|
|
func main() {
|
|
// Read client configuration from client_config.json
|
|
config, err := ReadConfig("config/client_config.json")
|
|
if err != nil {
|
|
fmt.Println("Error reading config:", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Initialize the client with the server address and username from the config
|
|
client := NewClient(config.ServerAddress, config.Username)
|
|
|
|
// Connect to the server
|
|
if err := client.Connect(); err != nil {
|
|
fmt.Println("Error connecting to server:", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Start listening for messages in a separate goroutine
|
|
go client.ListenForMessages()
|
|
|
|
// Launch the GUI
|
|
go ui.StartGUI()
|
|
|
|
// TODO: Implement channel joining and message sending logic
|
|
// TODO: Implement graceful shutdown logic
|
|
|
|
// Keep the main function running to keep the application alive
|
|
select {}
|
|
}
|