Skip to content

修复daemon模式参数不生效及增加host和port可选配置参数;#3

Open
Mickeywaugh wants to merge 6 commits intotourze:masterfrom
Mickeywaugh:master
Open

修复daemon模式参数不生效及增加host和port可选配置参数;#3
Mickeywaugh wants to merge 6 commits intotourze:masterfrom
Mickeywaugh:master

Conversation

@Mickeywaugh
Copy link

feat(command): 添加Workerman HTTP命令行选项支持

添加了对HTTP服务器的可配置选项支持,包括主机地址、端口和守护进程模式,
使用户能够自定义服务器监听地址和运行方式。
增加可通过环境变量.env设置主机和端口。

feat(command): 添加Workerman HTTP命令行选项支持

添加了对HTTP服务器的可配置选项支持,包括主机地址、端口和守护进程模式,
使用户能够自定义服务器监听地址和运行方式
```
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在增强 Workerman HTTP 服务器命令的灵活性和可用性。通过引入新的命令行选项和环境变量支持,用户现在可以更精细地控制服务器的监听地址、端口以及是否以守护进程模式运行,从而提升了部署和管理 Workerman 服务的便利性。

Highlights

  • 守护进程模式修复: 修复了 Workerman HTTP 服务器在 daemon 模式下参数不生效的问题,确保守护进程模式能够正确启用。
  • 新增配置选项: 为 Workerman HTTP 服务器添加了可配置的主机地址(host)和端口(port)选项,允许用户自定义服务器监听地址。
  • 环境变量支持: 支持通过命令行参数或 .env 环境变量设置 Workerman HTTP 服务器的主机和端口,提高了配置的灵活性。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/Command/WorkermanHttpCommand.php
    • 引入了 InputOption 类,用于定义命令行选项。
    • configure 方法中添加了 hostportdaemon 命令行选项,并设置了默认值。
    • 更新了 runHttpServer 方法,使其能够从命令行选项或环境变量中获取主机和端口配置,并根据 daemon 选项设置 Workerman 的守护进程模式。
Activity
  • 目前没有记录到任何活动。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次变更增加了对 Workerman HTTP 服务器的主机、端口和守护进程模式的命令行配置支持,并允许通过环境变量进行设置,提高了灵活性。代码实现清晰,优先使用环境变量,其次是命令行参数,这是很好的实践。我在审查中发现了一些可以改进的地方:一个是关于端口号的类型安全,另一个是建议为新功能添加测试。总体而言,这是一次不错的改进。

Comment on lines +77 to +79
->addOption('host', null, InputOption::VALUE_OPTIONAL, 'Host to listen on', '127.0.0.1')
->addOption('port', null, InputOption::VALUE_OPTIONAL, 'Port to listen on', 8080)
->addOption('daemon', 'd', InputOption::VALUE_NONE, 'Run in daemon mode')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这些新增的命令行选项很有用。为了确保其正确性和长期可维护性,建议在 tests/Command/WorkermanHttpCommandTest.php 中添加相应的测试用例。例如,可以在 testCommandConfiguration 方法中检查这些选项是否存在及其默认值。

{
$worker = new Worker('http://127.0.0.1:8080');
$host = $_ENV['WORKERMAN_HTTP_SERVER_HOST'] ?? $input->getOption('host');
$port = $_ENV['WORKERMAN_HTTP_SERVER_PORT'] ?? $input->getOption('port');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了增强代码的健壮性,建议将端口号显式转换为整数。从环境变量或命令行选项获取的值可能是字符串。如果提供了一个非数字的端口值,sprintf%d 格式化会将其转换为 0,这可能会导致服务器在非预期的端口上监听。显式转换可以更早地处理类型问题。

$port = (int) ($_ENV['WORKERMAN_HTTP_SERVER_PORT'] ?? $input->getOption('port'));

将端口号强制转换为整型,确保Worker构造函数接收正确的参数类型,
避免因环境变量或输入参数类型不一致导致的潜在错误。
更新 README.md 和 README.zh-CN.md 文件中的包名从
tourze/workerman-server-bundle 到 mickeywaugh/workerman-httpserver,
同时更新命令示例以包含默认的主机和端口参数。

更新所有源文件和测试文件中的命名空间从 Tourze 到 Mickeywaugh。
```
feat(command): 统一环境变量前缀并修复端口类型转换
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