| 1 | If built locally, dicedb works for as long as the build cache in the tmp |
| 2 | directory exists - it looks for a file called VERSION in the project root. |
| 3 | Once cleared, or in the case of downloading from substitute server, the |
| 4 | location of the VERSION file is invalid. Removing this code and instead |
| 5 | providing them through the flag resolves this issue. |
| 6 | |
| 7 | diff --git a/config/config.go b/config/config.go |
| 8 | index b358813..c408096 100644 |
| 9 | |
| 10 | |
| 11 | import ( |
| 12 | "os" |
| 13 | "path/filepath" |
| 14 | "reflect" |
| 15 | - "runtime" |
| 16 | - "strings" |
| 17 | |
| 18 | "github.com/spf13/pflag" |
| 19 | "github.com/spf13/viper" |
| 20 | var ( |
| 21 | DiceDBVersion = "-" |
| 22 | ) |
| 23 | |
| 24 | -// init initializes the DiceDBVersion variable by reading the |
| 25 | -// VERSION file from the project root. |
| 26 | -// This function runs automatically when the package is imported. |
| 27 | -func init() { |
| 28 | - // Get the absolute path of the current file (config.go) |
| 29 | - // using runtime reflection |
| 30 | - _, currentFile, _, _ := runtime.Caller(0) //nolint:dogsled |
| 31 | - |
| 32 | - // Navigate up two directories from config.go to reach the project root |
| 33 | - // (config.go is in the config/ directory, so we need to go up twice) |
| 34 | - projectRoot := filepath.Dir(filepath.Dir(currentFile)) |
| 35 | - |
| 36 | - // Read the VERSION file from the project root |
| 37 | - // This approach works regardless of where the program is executed from |
| 38 | - version, err := os.ReadFile(filepath.Join(projectRoot, "VERSION")) |
| 39 | - if err != nil { |
| 40 | - slog.Error("could not read the version file", slog.String("error", err.Error())) |
| 41 | - os.Exit(1) |
| 42 | - } |
| 43 | - |
| 44 | - // Store the version string in the package-level DiceDBVersion variable |
| 45 | - DiceDBVersion = strings.TrimSpace(string(version)) |
| 46 | -} |
| 47 | - |
| 48 | var Config *DiceDBConfig |
| 49 | |
| 50 | type DiceDBConfig struct { |