feat: add configuration checking

This commit is contained in:
Jonas Kaninda
2024-11-10 14:52:31 +01:00
parent 1a038ce0f5
commit a549e33e9a
9 changed files with 202 additions and 36 deletions

45
cmd/config/check.go Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright 2024 Jonas Kaninda
*
* 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 (
pkg "github.com/jkaninda/goma-gateway/internal"
"github.com/spf13/cobra"
"log"
)
var CheckConfigCmd = &cobra.Command{
Use: "check",
Short: "Check Goma Gateway configuration file",
Run: func(cmd *cobra.Command, args []string) {
configFile, _ := cmd.Flags().GetString("config")
if configFile == "" {
log.Fatalln("no config file specified")
}
err := pkg.CheckConfig(configFile)
if err != nil {
log.Fatalf(" Error checking config file: %s\n", err)
}
log.Println("Goma Gateway configuration file checked successfully")
},
}
func init() {
CheckConfigCmd.Flags().StringP("config", "c", "", "Path to the configuration filename")
}

View File

@@ -17,8 +17,8 @@ limitations under the License.
package config
import (
"github.com/jkaninda/goma-gateway/pkg/logger"
"github.com/spf13/cobra"
"log"
)
var Cmd = &cobra.Command{
@@ -28,7 +28,7 @@ var Cmd = &cobra.Command{
if len(args) == 0 {
return
} else {
logger.Fatal(`"config" accepts no argument %q`, args)
log.Fatalf("Config accepts no argument %q", args)
}
@@ -37,4 +37,5 @@ var Cmd = &cobra.Command{
func init() {
Cmd.AddCommand(InitConfigCmd)
Cmd.AddCommand(CheckConfigCmd)
}