From 0c9a300a58d9dacce7b84ff93222eed35eab5721 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Wed, 20 Jul 2022 16:07:13 +0200 Subject: Refactor: Do not log in internal packages The reason behind this is that we then do not have to pass a lot to each function. Logging inside internal packages is less useful as we want to let them return errors and only log in the 'public' facing API or let the client decide --- state.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'state.go') diff --git a/state.go b/state.go index 93cf217..2f7e785 100644 --- a/state.go +++ b/state.go @@ -59,15 +59,12 @@ func (state *VPNState) Register(name string, directory string, stateCallback fun } // Initialize the FSM - state.FSM.Init(name, stateCallback, &state.Logger, directory, debug) + state.FSM.Init(name, stateCallback, directory, debug) state.Debug = debug // Initialize the Config state.Config.Init(name, directory) - // Initialize Discovery - state.Discovery.Init(&state.FSM, &state.Logger) - // Try to load the previous configuration if state.Config.Load(&state) != nil { // This error can be safely ignored, as when the config does not load, the struct will not be filled @@ -153,7 +150,7 @@ func (state *VPNState) SetSecureLocation(countryCode string) error { return &types.WrappedErrorMessage{Message: "failed asking secure location", Err: serverErr} } - state.Servers.SetSecureLocation(server, &state.FSM, &state.Logger) + state.Servers.SetSecureLocation(server, &state.FSM) return nil } @@ -178,7 +175,7 @@ func (state *VPNState) addSecureInternetHomeServer(orgID string) (server.Server, } // Add the secure internet server - server, serverErr := state.Servers.AddSecureInternet(secureOrg, secureServer, &state.FSM, &state.Logger) + server, serverErr := state.Servers.AddSecureInternet(secureOrg, secureServer, &state.FSM) if serverErr != nil { return nil, &types.WrappedErrorMessage{Message: errorMessage, Err: serverErr} @@ -221,7 +218,7 @@ func (state *VPNState) addInstituteServer(url string) (server.Server, error) { return nil, &types.WrappedErrorMessage{Message: errorMessage, Err: discoErr} } // Add the secure internet server - server, serverErr := state.Servers.AddInstituteAccessServer(instituteServer, &state.FSM, &state.Logger) + server, serverErr := state.Servers.AddInstituteAccessServer(instituteServer, &state.FSM) if serverErr != nil { return nil, &types.WrappedErrorMessage{Message: errorMessage, Err: serverErr} @@ -238,7 +235,7 @@ func (state *VPNState) addCustomServer(url string) (server.Server, error) { customServer := &types.DiscoveryServer{BaseURL: url, DisplayName: map[string]string{"en": url}, Type: "custom_server"} // A custom server is just an institute access server under the hood - server, serverErr := state.Servers.AddCustomServer(customServer, &state.FSM, &state.Logger) + server, serverErr := state.Servers.AddCustomServer(customServer, &state.FSM) if serverErr != nil { return nil, &types.WrappedErrorMessage{Message: errorMessage, Err: serverErr} @@ -368,6 +365,7 @@ func (state *VPNState) SetDisconnected() error { } state.FSM.GoTransitionWithData(fsm.HAS_CONFIG, state.getServerInfoData(), false) + return nil } -- cgit v1.2.3