From c25efdd7d8e5abecb74ffe512c561b03d5a4e272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Sat, 21 Dec 2024 23:36:13 +0100 Subject: [PATCH] chore: modernize code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- cmd/daemon/root.go | 6 +++--- internal/httphandler/handler.go | 6 +++--- internal/openvpn/main.go | 2 +- internal/utils/testutils/main.go | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/daemon/root.go b/cmd/daemon/root.go index 9527bc0..559de8d 100644 --- a/cmd/daemon/root.go +++ b/cmd/daemon/root.go @@ -74,16 +74,16 @@ func Execute(args []string, logWriter io.Writer, version, commit, date string) i openvpnClient := openvpn.New(ctx, logger, conf) - oauth2Client, err := oauth2.New(ctx, logger, conf, httpClient, tokenStorage, provider, openvpnClient) + oAuth2Client, err := oauth2.New(ctx, logger, conf, httpClient, tokenStorage, provider, openvpnClient) if err != nil { logger.Error(err.Error()) return 1 } - openvpnClient.SetOAuth2Client(oauth2Client) + openvpnClient.SetOAuth2Client(oAuth2Client) - httpHandler, err := httphandler.New(conf, oauth2Client) + httpHandler, err := httphandler.New(conf, oAuth2Client) if err != nil { logger.Error(err.Error()) diff --git a/internal/httphandler/handler.go b/internal/httphandler/handler.go index 2f5270c..7bc54fe 100644 --- a/internal/httphandler/handler.go +++ b/internal/httphandler/handler.go @@ -11,7 +11,7 @@ import ( "github.com/jkroepke/openvpn-auth-oauth2/internal/ui" ) -func New(conf config.Config, oauth2 *oauth2.Client) (*http.ServeMux, error) { +func New(conf config.Config, oAuth2Client *oauth2.Client) (*http.ServeMux, error) { staticFs, err := fs.Sub(ui.Static, "assets") if err != nil { return nil, fmt.Errorf("failed to create static file system: %w", err) @@ -26,8 +26,8 @@ func New(conf config.Config, oauth2 *oauth2.Client) (*http.ServeMux, error) { _, _ = w.Write([]byte("OK")) })) mux.Handle(fmt.Sprintf("GET %s/assets/", basePath), http.StripPrefix(basePath+"/assets/", http.FileServerFS(staticFs))) - mux.Handle(fmt.Sprintf("GET %s/oauth2/start", basePath), noCacheHeaders(oauth2.OAuth2Start())) - mux.Handle(fmt.Sprintf("GET %s/oauth2/callback", basePath), noCacheHeaders(oauth2.OAuth2Callback())) + mux.Handle(fmt.Sprintf("GET %s/oauth2/start", basePath), noCacheHeaders(oAuth2Client.OAuth2Start())) + mux.Handle(fmt.Sprintf("GET %s/oauth2/callback", basePath), noCacheHeaders(oAuth2Client.OAuth2Callback())) return mux, nil } diff --git a/internal/openvpn/main.go b/internal/openvpn/main.go index 7a98785..7e4f035 100644 --- a/internal/openvpn/main.go +++ b/internal/openvpn/main.go @@ -43,7 +43,7 @@ func New(ctx context.Context, logger *slog.Logger, conf config.Config) *Client { return client } -func (c *Client) SetOAuth2Client(client oauth2Client) { +func (c *Client) SetOAuth2Client(client oAuth2Client) { c.oauth2 = client } diff --git a/internal/utils/testutils/main.go b/internal/utils/testutils/main.go index 85bdeeb..3d2bc81 100644 --- a/internal/utils/testutils/main.go +++ b/internal/utils/testutils/main.go @@ -346,12 +346,12 @@ func SetupOpenVPNOAuth2Clients( require.NoError(tb, err) openVPNClient := openvpn.New(ctx, logger, conf) - oauth2Client, err := oauth2.New(ctx, logger, conf, httpClient, tokenStorage, provider, openVPNClient) + oAuth2Client, err := oauth2.New(ctx, logger, conf, httpClient, tokenStorage, provider, openVPNClient) require.NoError(tb, err) - openVPNClient.SetOAuth2Client(oauth2Client) + openVPNClient.SetOAuth2Client(oAuth2Client) tb.Cleanup(openVPNClient.Shutdown) - return oauth2Client, openVPNClient + return oAuth2Client, openVPNClient }