-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
49 lines (45 loc) · 1002 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"encoding/json"
"flag"
"log"
"os"
"strings"
"github.com/pelletier/go-toml/v2"
)
func sshmuxServer(configFile string) (*Server, error) {
var config Config
configFileBytes, err := os.ReadFile(configFile)
if err != nil {
return nil, err
}
if strings.HasSuffix(configFile, ".toml") {
err = toml.Unmarshal(configFileBytes, &config)
if err != nil {
return nil, err
}
} else {
log.Println("warning: The `config.json` API is deprecated. Please use `config.toml` instead.")
var legacyConfig LegacyConfig
err = json.Unmarshal(configFileBytes, &legacyConfig)
if err != nil {
return nil, err
}
config = convertLegacyConfig(legacyConfig)
}
return makeServer(config)
}
func main() {
var configFile string
flag.StringVar(&configFile, "c", "/etc/sshmux/config.toml", "config file")
flag.Parse()
sshmux, err := sshmuxServer(configFile)
if err != nil {
log.Fatal(err)
}
err = sshmux.Start()
if err != nil {
log.Fatal(err)
}
sshmux.Wait()
}