add config
This commit is contained in:
parent
8bd84176be
commit
a2d2833c45
|
@ -1,7 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gommunicator/internal/communicator"
|
||||
"gommunicator/internal/config"
|
||||
"gommunicator/internal/input"
|
||||
"gommunicator/internal/logger"
|
||||
"gommunicator/internal/memory"
|
||||
|
@ -20,17 +24,29 @@ QeekJS54FkHRqN62vXeEAAAADnlhc2hAeWFzaC1hc3VzAQIDBAUGBw==
|
|||
func main() {
|
||||
log := logger.SetupLogger("prod")
|
||||
|
||||
cfg := config.MustParse()
|
||||
|
||||
mem := memory.New()
|
||||
communicator := communicator.New().WithDefaultServerClient()
|
||||
uc := usecase.New(log, mem, communicator)
|
||||
|
||||
go input.New(uc, log).Run()
|
||||
|
||||
readServerPrivateKey(cfg.KeyFile)
|
||||
|
||||
srv, err := ssh.New(log, uc, []byte(key))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := srv.Start("127.0.0.1:8022"); err != nil {
|
||||
if err := srv.Start(cfg.ServerAddr); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func readServerPrivateKey(filename string) (string, error) {
|
||||
file, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read private key in '%s': %w", filename, err)
|
||||
}
|
||||
return string(file), nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package config
|
||||
|
||||
import "flag"
|
||||
|
||||
type Config struct {
|
||||
KeyFile string
|
||||
ServerAddr string // "127.0.0.1:8022"
|
||||
}
|
||||
|
||||
func MustParse() *Config {
|
||||
var cfg Config
|
||||
|
||||
flag.StringVar(&cfg.KeyFile, "key", "~/.ssh/id_rsa", "private server key")
|
||||
flag.StringVar(&cfg.ServerAddr, "addr", "0.0.0.0:8022", "listen address")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
return &cfg
|
||||
}
|
|
@ -33,11 +33,11 @@ func (i *Input) Run() {
|
|||
continue
|
||||
}
|
||||
// observe command
|
||||
if msg[0] == '/' || msg == "?" {
|
||||
if msg[0] == '/' || msg[0] == '?' {
|
||||
switch msg {
|
||||
case "?", "/help":
|
||||
case "?\n", "/help\n":
|
||||
fmt.Println(helpMessage)
|
||||
case "/new-password":
|
||||
case "/new-password\n":
|
||||
pass, err := i.uc.GenNewPassword()
|
||||
if err != nil {
|
||||
i.log.Error("failed to generate new client's password", "err", err)
|
||||
|
|
Loading…
Reference in New Issue