feat: refactor server initialization and directory creation logic#2
Merged
feat: refactor server initialization and directory creation logic#2
Conversation
Signed-off-by: cfc4n <cfc4n.cs@gmail.com>
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the server initialization and directory creation logic to simplify the code and centralize directory creation into a single utility. Key changes include:
- Removal of the CheckDirectory function from services/utils.go and introduction of CreateDirectory in cli/cmd/utils.go.
- Adjustments to MoLingConfig structure and updates to directory creation logic in CLI commands (root.go, perrun.go, moling_test.go) and server initialization in moling.go.
Reviewed Changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| services/utils.go | Removed CheckDirectory in favor of a more central directory creation logic. |
| services/config.go | Updated MoLingConfig, adding ListenAddr and modifying BasePath comments. |
| cli/cmd/utils.go | Introduced CreateDirectory to handle directory creation. |
| cli/cmd/root.go | Revised pre-run logic to use the new CreateDirectory and set BasePath using the current user. |
| cli/cmd/perrun.go | Renamed and updated pre-run function for directory creation. |
| cli/cmd/moling.go | Updated NewMoLingServer to remove the explicit listenAddr parameter. |
| cli/cmd/moling_test.go | Updated tests to match changes in directory creation and server initialization. |
Files not reviewed (2)
- Makefile: Language not supported
- variables.mk: Language not supported
Comments suppressed due to low confidence (1)
cli/cmd/perrun.go:25
- [nitpick] The function name 'mlsCommandPreFunc' is not very descriptive; consider renaming it to something like 'preRunCreateDirectories' to clarify its purpose.
func mlsCommandPreFunc(cmd *cobra.Command, args []string) error {
| //rootCmd.PersistentFlags().StringSliceVar(&mlConfig.AllowDir, "allow-dir", []string{"/tmp"}, "allow dir") | ||
| rootCmd.PersistentFlags().StringVarP(&listenAddr, "listen", "l", "", "listen address,aka SSE mode. if not set, use STDIO mode") | ||
| //rootCmd.PersistentFlags().StringVarP(&mlConfig.ConfigFile, "config_file", "c", "config.json", "MoLing Config File Path") | ||
| rootCmd.PersistentFlags().StringVar(&mlConfig.BasePath, "base_path", mlConfig.BasePath, "MoLing Base Data Path, automatically set by the system, cannot be changed, display only.") |
There was a problem hiding this comment.
The base_path flag is documented as display-only, yet using a persistent flag allows its value to be overridden. Consider marking the flag as hidden or removing it to enforce read-only behavior.
Suggested change
| rootCmd.PersistentFlags().StringVar(&mlConfig.BasePath, "base_path", mlConfig.BasePath, "MoLing Base Data Path, automatically set by the system, cannot be changed, display only.") | |
| rootCmd.PersistentFlags().StringVar(&mlConfig.BasePath, "base_path", mlConfig.BasePath, "MoLing Base Data Path, automatically set by the system, cannot be changed, display only.") | |
| rootCmd.PersistentFlags().MarkHidden("base_path") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.