Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to read config properly #153

Open
yunkon-kim opened this issue Sep 27, 2021 · 6 comments
Open

Need to read config properly #153

yunkon-kim opened this issue Sep 27, 2021 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@yunkon-kim
Copy link
Member

What would you like to be enhanced
: I'd like to read config properly.

Why is this needed
: The config setting code is redundant in many init().

Proposed solution
:

@yunkon-kim yunkon-kim added enhancement New feature or request help wanted Extra attention is needed labels Sep 27, 2021
@ChobobDev
Copy link
Member

I would like to know more about this issue since I am interested in working on this topic.

Thank you

@yunkon-kim
Copy link
Member Author

yunkon-kim commented Oct 11, 2021

@ChobobDev I'm happy to hear that 😄

I'm looking for a nice way to set configs.

At the very beginning, I wanted to protect critical information and modify it easily by users so that I create the below configs.

  • config.yaml for poc-cb-net
  • log_conf.yaml for cb-log (external package)

With these configs, users can run several executable files (e.g., admin-web, controller, agent, clad-service) in any directory. (CB-Larva, which aims for microservice architecture, is divided into executable files.) Even when I run the controller on a Docker container, it's fine ^^

But... The problem is that I have many duplicated init() functions... That's why I'm looking for a nice way to set configs.

I would like to follow Golang's package programming philosophy and discuss ways to improve it with you ^^

If you have any further questions, comments, and concerns, feel free to tell me 😄

@yunkon-kim
Copy link
Member Author

[Additional description]

On develop branch, below files have related init() function.

An example of init() (Each init() would be slightly different.)

func init() {
	fmt.Println("Start......... init() of controller.go")
	ex, err := os.Executable()
	if err != nil {
		panic(err)
	}
	exePath := filepath.Dir(ex)
	fmt.Printf("exePath: %v\n", exePath)

	// Load cb-log config from the current directory (usually for the production)
	logConfPath := filepath.Join(exePath, "config", "log_conf.yaml")
	fmt.Printf("logConfPath: %v\n", logConfPath)
	if !file.Exists(logConfPath) {
		// Load cb-log config from the project directory (usually for development)
		path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
		if err != nil {
			panic(err)
		}
		projectPath := strings.TrimSpace(string(path))
		logConfPath = filepath.Join(projectPath, "poc-cb-net", "config", "log_conf.yaml")
	}
	CBLogger = cblog.GetLoggerWithConfigPath("cb-network", logConfPath)
	CBLogger.Debugf("Load %v", logConfPath)

	// Load cb-network config from the current directory (usually for the production)
	configPath := filepath.Join(exePath, "config", "config.yaml")
	fmt.Printf("configPath: %v\n", configPath)
	if !file.Exists(configPath) {
		// Load cb-network config from the project directory (usually for the development)
		path, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
		if err != nil {
			panic(err)
		}
		projectPath := strings.TrimSpace(string(path))
		configPath = filepath.Join(projectPath, "poc-cb-net", "config", "config.yaml")
	}
	config, _ = model.LoadConfig(configPath)
	CBLogger.Debugf("Load %v", configPath)
	fmt.Println("End......... init() of controller.go")
}

@yunkon-kim
Copy link
Member Author

Hi, @ChobobDev

If you are working on this issue, could you share your progress? 😄

@ChobobDev
Copy link
Member

I am sorry @hermitkim1 I am still trying to understand this issue.
So I do not have clear progress on this issue.
I would love to ask for your warm understanding.

Thank You

@yunkon-kim
Copy link
Member Author

@ChobobDev, I fully understand your difficulty on this issue ☺️

If you have any discussion points, feel free to tell me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants