From 2467c353183b835dc0954d268ca47f9b50fae1ca Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 19 Aug 2024 08:00:00 +0800 Subject: [PATCH] {config,oidc}.go: Simplify error handling again --- config.go | 6 ++---- oidc.go | 15 +++++---------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/config.go b/config.go index 71b791f..589627c 100644 --- a/config.go +++ b/config.go @@ -78,11 +78,9 @@ var config struct { } func fbfp_get_config(path string) { - f, err := os.Open(path) - e(err) + f := er(os.Open(path)) - err = scfg.NewDecoder(bufio.NewReader(f)).Decode(&config_with_pointers) - e(err) + e(scfg.NewDecoder(bufio.NewReader(f)).Decode(&config_with_pointers)) /* * TODO: We segfault when there are missing configuration options. diff --git a/oidc.go b/oidc.go index aeb2304..3e59f8c 100644 --- a/oidc.go +++ b/oidc.go @@ -58,8 +58,7 @@ type msclaims_t struct { * - https://accounts.google.com/.well-known/openid-configuration */ func get_openid_config(endpoint string) { - resp, err := http.Get(endpoint + "/.well-known/openid-configuration") - e(err) + resp := er(http.Get(endpoint + "/.well-known/openid-configuration")) defer resp.Body.Close() if resp.StatusCode != 200 { log.Fatal(fmt.Sprintf( @@ -67,11 +66,9 @@ func get_openid_config(endpoint string) { resp.StatusCode, )) } - err = json.NewDecoder(resp.Body).Decode(&openid_configuration) - e(err) + e(json.NewDecoder(resp.Body).Decode(&openid_configuration)) - resp, err = http.Get(openid_configuration.JwksUri) - e(err) + resp = er(http.Get(openid_configuration.JwksUri)) defer resp.Body.Close() if resp.StatusCode != 200 { log.Fatal(fmt.Sprintf( @@ -85,8 +82,7 @@ func get_openid_config(endpoint string) { config.Openid.Authorize } - jwks_json, err := io.ReadAll(resp.Body) - e(err) + jwks_json := er(io.ReadAll(resp.Body)) /* * TODO: The key set is never updated, which is technically incorrect. @@ -94,8 +90,7 @@ func get_openid_config(endpoint string) { * controlling when to do it manually. Remember to wrap it around a * mutex or some semaphores though. */ - openid_keyfunc, err = keyfunc.NewJWKSetJSON(jwks_json) - e(err) + openid_keyfunc = er(keyfunc.NewJWKSetJSON(jwks_json)) } func generate_authorization_url() string { -- 2.11.4.GIT