File tree Expand file tree Collapse file tree 3 files changed +30
-12
lines changed
internal/gostx/config/parsing/parser Expand file tree Collapse file tree 3 files changed +30
-12
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
1010 "strings"
1111 "syscall"
1212
13+ defaults "github.com/greyhavenhq/greyproxy"
1314 "github.com/greyhavenhq/greyproxy/internal/gostcore/logger"
1415 "github.com/greyhavenhq/greyproxy/internal/gostcore/service"
1516 greyproxy "github.com/greyhavenhq/greyproxy/internal/greyproxy"
@@ -37,12 +38,13 @@ type program struct {
3738
3839func (p * program ) Init (env svc.Environment ) error {
3940 parser .Init (parser.Args {
40- CfgFile : cfgFile ,
41- Services : services ,
42- Nodes : nodes ,
43- Debug : debug ,
44- Trace : trace ,
45- MetricsAddr : metricsAddr ,
41+ CfgFile : cfgFile ,
42+ DefaultConfig : defaults .DefaultConfig ,
43+ Services : services ,
44+ Nodes : nodes ,
45+ Debug : debug ,
46+ Trace : trace ,
47+ MetricsAddr : metricsAddr ,
4648 })
4749
4850 return nil
Original file line number Diff line number Diff line change 1+ package greyproxy
2+
3+ import _ "embed"
4+
5+ // DefaultConfig is the embedded default greyproxy.yml configuration.
6+ // It is used when no -C flag is provided on the command line.
7+ //
8+ //go:embed greyproxy.yml
9+ var DefaultConfig []byte
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package parser
22
33import (
44 "bufio"
5+ "bytes"
56 "encoding/json"
67 "os"
78 "strings"
@@ -28,12 +29,13 @@ func Parse() (*config.Config, error) {
2829}
2930
3031type Args struct {
31- CfgFile string
32- Services []string
33- Nodes []string
34- Debug bool
35- Trace bool
36- MetricsAddr string
32+ CfgFile string
33+ DefaultConfig []byte // embedded default config (used when CfgFile is empty)
34+ Services []string
35+ Nodes []string
36+ Debug bool
37+ Trace bool
38+ MetricsAddr string
3739}
3840
3941type parser struct {
@@ -68,6 +70,11 @@ func (p *parser) Parse() (*config.Config, error) {
6870 return nil , err
6971 }
7072 }
73+ } else if len (p .args .DefaultConfig ) > 0 {
74+ // No -C flag: use the embedded default configuration.
75+ if err := cfg .Read (bytes .NewReader (p .args .DefaultConfig ), "yaml" ); err != nil {
76+ return nil , err
77+ }
7178 }
7279
7380 cmdCfg , err := cmd .BuildConfigFromCmd (p .args .Services , p .args .Nodes )
You can’t perform that action at this time.
0 commit comments