Skip to content

Commit

Permalink
Added config validation in service init method
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Mar 21, 2023
1 parent 7e6d33b commit f2266f4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func (n *Node) Start() error {
}()

go func() {
if err := n.jobUpdateStatus(); err != nil {
if err := n.jobUpdateSessions(); err != nil {
panic(err)
}
}()

go func() {
if err := n.jobUpdateSessions(); err != nil {
if err := n.jobUpdateStatus(); err != nil {
panic(err)
}
}()
Expand Down
1 change: 0 additions & 1 deletion services/v2ray/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strings"
)

// nolint:lll
var (
configTemplate = strings.TrimSpace(`
{
Expand Down
5 changes: 4 additions & 1 deletion services/v2ray/v2ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ func (s *V2Ray) Init(home string) (err error) {
if err != nil {
return err
}
if err = s.config.Validate(); err != nil {
return err
}

t, err := template.New("wireguard_conf").Parse(configTemplate)
t, err := template.New("v2ray_json").Parse(configTemplate)
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion services/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ func (s *WireGuard) Init(home string) (err error) {
if err != nil {
return err
}
if err = s.cfg.Validate(); err != nil {
return err
}

t, err := template.New("v2ray_json").Parse(configTemplate)
t, err := template.New("wireguard_conf").Parse(configTemplate)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ func ListenAndServeTLS(address, certFile, keyFile string, handler http.Handler)
anyMux = mux.Match(cmux.Any())
)

go func() {
if err := http.Serve(
anyMux,
handler,
); err != nil {
panic(err)
}
}()

go func() {
if err := http.Serve(
tls.NewListener(
Expand All @@ -52,5 +43,14 @@ func ListenAndServeTLS(address, certFile, keyFile string, handler http.Handler)
}
}()

go func() {
if err := http.Serve(
anyMux,
handler,
); err != nil {
panic(err)
}
}()

return mux.Serve()
}

0 comments on commit f2266f4

Please sign in to comment.