Restored progress
This commit is contained in:
parent
f615cff76d
commit
5244f87411
19 changed files with 1061 additions and 0 deletions
42
internal/client/client.go
Normal file
42
internal/client/client.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package client
|
||||
|
||||
|
||||
import (
|
||||
"log"
|
||||
"cosync/internal/core"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//TODO: handle errors, review logging
|
||||
func Run() {
|
||||
|
||||
log.Println("Loading config")
|
||||
|
||||
// Loading config into program
|
||||
err := core.LoadConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
config := core.GetConfig()
|
||||
|
||||
log.Println("Loaded")
|
||||
|
||||
serverAddress := config["server"].(string)
|
||||
serverPort := strconv.Itoa(config["port"].(int))
|
||||
|
||||
log.Println("Connecting to server")
|
||||
|
||||
// Connect to the server
|
||||
conn, err := net.Dial("tcp", serverAddress + ":" + serverPort)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
log.Println("Connected")
|
||||
|
||||
conn.Write([]byte("Hello server"))
|
||||
}
|
||||
104
internal/client/setup.go
Normal file
104
internal/client/setup.go
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"cosync/internal/core"
|
||||
)
|
||||
|
||||
const (
|
||||
colorRed = "\033[0;31m"
|
||||
colorGreen = "\033[1;32m"
|
||||
colorNone = "\033[0m"
|
||||
separator = "\n ============================================== \n\n"
|
||||
)
|
||||
|
||||
func Setup() {
|
||||
|
||||
// Print logo
|
||||
println(" ______ ______ \n .' ___ | .' ____ \\ \n/ .' \\_| .--. | (___ \\_| _ __ _ .--. .---. \n| | / .'`\\ \\ _.____`. [ \\ [ ][ `.-. | / /'`\\] \n\\ `.___.'\\| \\__. || \\____) | \\ '/ / | | | | | \\__. \n `.____ .' '.__.' \\______.'[\\_: / [___||__]'.___.' \n \\__.' ")
|
||||
print(separator)
|
||||
|
||||
// Greeting
|
||||
println("Hi, welcome to cosync, let's set it up")
|
||||
println("Don't hesitate to give a look at the doc to know how it works ! :) \n -> https://docs.oblic-parallels.fr/cosync\n")
|
||||
|
||||
// Try create config files
|
||||
err := core.MkConfig()
|
||||
if err != nil {
|
||||
println(colorRed + "Setup: Failed to create config files" + colorNone)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Prompt for server/port assignation
|
||||
print("Server address: ")
|
||||
// ...
|
||||
print("Port")
|
||||
// ...
|
||||
|
||||
// Update config file accordingly
|
||||
// ...
|
||||
println(colorGreen + "Config has been updated with new values" + colorNone)
|
||||
|
||||
// Prompt to start service
|
||||
print("Do you want to start CoSync now ? [Y/n]: ")
|
||||
//...
|
||||
}
|
||||
|
||||
//! This code no longer needs to exist as config is now handled by cosync/config
|
||||
// Then it will be removed soon
|
||||
|
||||
// func mkConfigFiles(configFolderPath string, configFileName string, syncFileName string) {
|
||||
|
||||
// // Check if folder already exists
|
||||
// _, err := os.Stat(configFolderPath)
|
||||
// if err != nil && os.IsNotExist(err) {
|
||||
// // Create config folder
|
||||
// err = os.Mkdir(configFolderPath, os.ModePerm)
|
||||
// if err != nil {
|
||||
// println(colorRed + "\n\nCouldn't create the config folder" + colorNone)
|
||||
// panic("Setup: Couldn't create " + configFolderPath + " -> " + err.Error())
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Check if config file exists
|
||||
// configFilePath := configFolderPath + configFileName
|
||||
// _, err = os.Stat(configFilePath)
|
||||
// if err != nil && os.IsNotExist(err) {
|
||||
// // Create config file
|
||||
// _, err = os.Create(configFilePath)
|
||||
// if err != nil {
|
||||
// println(colorRed + "\n\nCouldn't create the config file" + colorNone)
|
||||
// panic("Setup: Couldn't create " + configFilePath + " -> " + err.Error())
|
||||
// }
|
||||
// }
|
||||
|
||||
// syncFilePath := configFolderPath + syncFileName
|
||||
// _, err = os.Stat(syncFilePath)
|
||||
// if err != nil && os.IsNotExist(err) {
|
||||
// // Create config folder
|
||||
// _, err = os.Create(syncFilePath)
|
||||
// if err != nil {
|
||||
// println(colorRed + "\n\nCouldn't create the sync file" + colorNone)
|
||||
// panic("Setup: Couldn't create " + syncFilePath + " -> " + err.Error())
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// func WriteDefaultConfig(configFilePath string) {
|
||||
|
||||
// // Open file
|
||||
// f, err := os.Open(configFilePath)
|
||||
// if err != nil {
|
||||
// println(colorRed + "\n\nCouldn't open the config file" + colorNone)
|
||||
// panic("Setup: Couldn't access " + configFilePath + " -> " + err.Error())
|
||||
// }
|
||||
// defer f.Close()
|
||||
|
||||
// // Write file
|
||||
// // TODO: import pre existing config file
|
||||
// _, err = f.WriteString("{}")
|
||||
// if err != nil {
|
||||
// println(colorRed + "\n\nCouldn't open the config file" + colorNone)
|
||||
// panic("Setup: Couldn't access " + configFilePath + " -> " + err.Error())
|
||||
// }
|
||||
// }
|
||||
Loading…
Add table
Add a link
Reference in a new issue