🎨 Use os.readfile instead of ioutil
This commit is contained in:
parent
c51a17993e
commit
a871f165b7
|
@ -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
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -45,7 +58,7 @@ func LoadConfig() error {
|
||||||
loadConfigFromEnvOrSecrets(GlobalConfig)
|
loadConfigFromEnvOrSecrets(GlobalConfig)
|
||||||
|
|
||||||
// Check if the configuration has been loaded successfully
|
// 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
|
// Add more checks as necessary for other required config fields
|
||||||
return errors.New("failed to load configuration from any source")
|
return errors.New("failed to load configuration from any source")
|
||||||
}
|
}
|
||||||
|
@ -54,7 +67,7 @@ func LoadConfig() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfigFromFile(filePath string, config *AppConfig) error {
|
func loadConfigFromFile(filePath string, config *AppConfig) error {
|
||||||
fileData, err := ioutil.ReadFile(filePath)
|
fileData, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -81,7 +94,7 @@ func loadConfigFromEnvOrSecrets(config *AppConfig) {
|
||||||
// Handling Docker secrets (file-based secrets)
|
// Handling Docker secrets (file-based secrets)
|
||||||
secretFileEnvVar := envVar + "_FILE"
|
secretFileEnvVar := envVar + "_FILE"
|
||||||
if secretFilePath, exists := os.LookupEnv(secretFileEnvVar); exists {
|
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))
|
val.Field(i).SetString(string(secretValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue