File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,16 @@ package cmd
22
33import (
44 "context"
5+ "log/slog"
6+ "os"
57
68 "github.com/alecthomas/kong"
79 "github.com/cedws/sshgate/pkg/sshgate"
810)
911
1012type cli struct {
1113 ListenAddr string `help:"Address to listen on" default:":2222"`
14+ LogFormat string `help:"Log format"`
1215 Config string `help:"Path to JSON config file"`
1316
1417 Serve serveCmd `cmd:"" default:"1" help:"Start the server"`
@@ -18,7 +21,20 @@ type cli struct {
1821type serveCmd struct {}
1922
2023func (s * serveCmd ) Run (c * cli ) error {
21- config , err := sshgate .Open (c .Config )
24+ var handler slog.Handler
25+
26+ switch c .LogFormat {
27+ case "json" :
28+ handler = slog .NewJSONHandler (os .Stderr , nil )
29+ case "text" :
30+ fallthrough
31+ default :
32+ handler = slog .NewTextHandler (os .Stderr , nil )
33+ }
34+
35+ slog .SetDefault (slog .New (handler ))
36+
37+ config , err := sshgate .ReadConfig (c .Config )
2238 if err != nil {
2339 return err
2440 }
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ func (c Config) Validate() error {
4848 return nil
4949}
5050
51- func Open (path string ) (* Config , error ) {
51+ func ReadConfig (path string ) (* Config , error ) {
5252 data , err := os .ReadFile (path )
5353 if err != nil {
5454 return nil , fmt .Errorf ("failed to read config file: %w" , err )
You can’t perform that action at this time.
0 commit comments