Skip to content

Conversation

@Sn0w3y
Copy link

@Sn0w3y Sn0w3y commented Dec 29, 2025

This commit enhances the initialization process and error handling across various components of the system. Changes include the addition of error checks during the initialization phase in main.go, ensuring that the system halts with an appropriate error message if any part of the setup (config, database, services) fails. Additionally, the logging mechanism has been improved to use structured logging for better clarity and debugging. The config initialization now returns an error if it fails, promoting better error handling practices. Similarly, database connection errors are now properly handled, and the system will return a specific error if the connection fails. These changes aim to make the system more robust by ensuring that startup errors are clearly reported and logged, facilitating easier troubleshooting and enhancing overall system reliability.

This commit enhances the initialization process and error handling across various components of the system. Changes include the addition of error checks during the initialization phase in main.go, ensuring that the system halts with an appropriate error message if any part of the setup (config, database, services) fails. Additionally, the logging mechanism has been improved to use structured logging for better clarity and debugging. The config initialization now returns an error if it fails, promoting better error handling practices. Similarly, database connection errors are now properly handled, and the system will return a specific error if the connection fails. These changes aim to make the system more robust by ensuring that startup errors are clearly reported and logged, facilitating easier troubleshooting and enhancing overall system reliability.
This commit introduces several key changes aimed at optimizing file handling and improving code readability across various components. Notably, it includes the following modifications:

1. In `main.go`, a comment was added to clarify the purpose of the `embed` import, enhancing code understandability.

2. `pkg/config/init.go` saw a significant refactor in the configuration file's initialization process. The method now uses `os.OpenFile` with `O_EXCL` flag for atomic creation, reducing the risk of race conditions and simplifying error handling.

3. `pkg/utils/file/file.go` received multiple updates, including the removal of duplicate imports, introduction of a new function `readDirInfo` for efficient directory reading, and various optimizations in file and directory handling functions to improve performance and readability.

4. Adjustments in `pkg/utils/httper/zerotier.go`, `route/v1/file.go`, and `route/v1/system.go` were made to simplify parameter passing and enhance consistency in function signatures.

5. General code cleanup was performed, including the removal of unused imports and redundant code, and transitioning to `io.ReadAll` from `ioutil.ReadAll` following the deprecation of `ioutil` in Go 1.16.

These changes collectively aim to make the codebase more efficient, readable, and maintainable.
This commit introduces several key changes to both the file handling logic and the HTTP header management for file downloads. In `pkg/utils/file/file.go`, the `CopyDir` function has been renamed to more accurately reflect its purpose, and its implementation has been refactored for clarity and efficiency. A new helper function, `copyDirContents`, has been added to streamline the process of copying the contents of a directory. Additionally, `copyEntry` has been introduced to handle the copying of individual directory entries, whether they are files or directories, simplifying the logic within `CopyDir` and `copyDirContents`.

In `route/v1/file.go`, constants for HTTP headers related to file downloads have been defined to replace hard-coded strings, improving code readability and maintainability. This change ensures that the header keys and values are consistent and centrally managed, reducing the likelihood of errors and making the codebase easier to understand and modify.
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant