From a871f165b7bb3a10c376c4c2ea0939e2b08557f1 Mon Sep 17 00:00:00 2001 From: Florian Beisel Date: Sun, 21 Jan 2024 14:58:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Use=20os.readfile=20instead=20of?= =?UTF-8?q?=20ioutil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 9848647..f3c82a2 100644 --- a/config/config.go +++ b/config/config.go @@ -1,10 +1,23 @@ +// Copyright 2024 Florian Beisel +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package config import ( "encoding/json" "errors" "flag" - "io/ioutil" "os" "reflect" "strings" @@ -45,7 +58,7 @@ func LoadConfig() error { loadConfigFromEnvOrSecrets(GlobalConfig) // Check if the configuration has been loaded successfully - if GlobalConfig.JwtKey == "" || GlobalConfig.DatabaseFile == "" { + if GlobalConfig.DatabaseFile == "" { // Add more checks as necessary for other required config fields return errors.New("failed to load configuration from any source") } @@ -54,7 +67,7 @@ func LoadConfig() error { } func loadConfigFromFile(filePath string, config *AppConfig) error { - fileData, err := ioutil.ReadFile(filePath) + fileData, err := os.ReadFile(filePath) if err != nil { return err } @@ -81,7 +94,7 @@ func loadConfigFromEnvOrSecrets(config *AppConfig) { // Handling Docker secrets (file-based secrets) secretFileEnvVar := envVar + "_FILE" if secretFilePath, exists := os.LookupEnv(secretFileEnvVar); exists { - if secretValue, err := ioutil.ReadFile(secretFilePath); err == nil { + if secretValue, err := os.ReadFile(secretFilePath); err == nil { val.Field(i).SetString(string(secretValue)) } }