Removed client subdirectory from monorepo into its own repository.

Renamed "server" subdirectory to "src" as this entire derectory now only has server code.
Removed "bin" directory to project root.
Moved Dockerfile to project root.
This commit is contained in:
Kelvin Clement Mwinuka
2023-11-10 22:42:23 +08:00
parent e505361ef6
commit 974fc24617
21 changed files with 22 additions and 398 deletions

87
src/utils/config.go Normal file
View File

@@ -0,0 +1,87 @@
package utils
import (
"encoding/json"
"flag"
"os"
"path"
"gopkg.in/yaml.v3"
)
type Config struct {
TLS bool `json:"tls" yaml:"tls"`
Key string `json:"key" yaml:"key"`
Cert string `json:"cert" yaml:"cert"`
Port uint16 `json:"port" yaml:"port"`
HTTP bool `json:"http" yaml:"http"`
PluginDir string `json:"plugins" yaml:"plugins"`
ServerID string `json:"serverId" yaml:"serverId"`
JoinAddr string `json:"joinAddr" yaml:"joinAddr"`
BindAddr string `json:"bindAddr" yaml:"bindAddr"`
RaftBindPort uint16 `json:"raftPort" yaml:"raftPort"`
MemberListBindPort uint16 `json:"mlPort" yaml:"mlPort"`
InMemory bool `json:"inMemory" yaml:"inMemory"`
DataDir string `json:"dataDir" yaml:"dataDir"`
}
func GetConfig() Config {
tls := flag.Bool("tls", false, "Start the server in TLS mode. Default is false")
key := flag.String("key", "", "The private key file path.")
cert := flag.String("cert", "", "The signed certificate file path.")
port := flag.Int("port", 7480, "Port to use. Default is 7480")
http := flag.Bool("http", false, "Use HTTP protocol instead of raw TCP. Default is false")
pluginDir := flag.String("pluginDir", "", "Directory where plugins are located.")
serverId := flag.String("serverId", "1", "Server ID in raft cluster. Leave empty for client.")
joinAddr := flag.String("joinAddr", "", "Address of cluster member in a cluster to you want to join.")
bindAddr := flag.String("bindAddr", "", "Address to bind the server to.")
raftBindPort := flag.Int("raftPort", 7481, "Port to use for intra-cluster communication. Leave on the client.")
mlBindPort := flag.Int("mlPort", 7946, "Port to use for memberlist communication.")
inMemory := flag.Bool("inMemory", false, "Wether to use memory or persisten storage for raft logs and snapshots.")
dataDir := flag.String("dataDir", "/var/lib/memstore", "Directory to store raft snapshots and logs.")
config := flag.String(
"config",
"",
`File path to a JSON or YAML config file.The values in this config file will override the flag values.`,
)
flag.Parse()
conf := Config{
TLS: *tls,
Key: *key,
Cert: *cert,
HTTP: *http,
PluginDir: *pluginDir,
Port: uint16(*port),
ServerID: *serverId,
JoinAddr: *joinAddr,
BindAddr: *bindAddr,
RaftBindPort: uint16(*raftBindPort),
MemberListBindPort: uint16(*mlBindPort),
InMemory: *inMemory,
DataDir: *dataDir,
}
if len(*config) > 0 {
// Override configurations from file
if f, err := os.Open(*config); err != nil {
panic(err)
} else {
defer f.Close()
ext := path.Ext(f.Name())
if ext == ".json" {
json.NewDecoder(f).Decode(&conf)
}
if ext == ".yaml" || ext == ".yml" {
yaml.NewDecoder(f).Decode(&conf)
}
}
}
return conf
}