pingora icon indicating copy to clipboard operation
pingora copied to clipboard

快速入门指南中的示例代码问题

Open zjwztttt opened this issue 11 months ago • 4 comments

Describe the bug

在入门指南示例代码中的下面一行源码缺少一对花括号“{}”,比如: println!("upstream peer is: {:upstream?}"); 应该改成: println!("upstream peer is: {{:upstream?}}");

Pingora info

Please include the following information about your environment:

Pingora version: 0.1 Rust version: 1.76 Operating system version: Debian 12.4

报以下错误

error: invalid format string: expected '}', found '?' --> src/main.rs:21:47 | 21 | println!("upstream peer is: {:upstream?}"); | - ^ expected '}' in format string | | | because of this opening brace | = note: if you intended to print {, you can escape it using {{

error: could not compile load_balancer (bin "load_balancer") due to 1 previous error

zjwztttt avatar Mar 04 '24 11:03 zjwztttt

上面解决办法写完后发现错了,实际正确的解决方法是改成以下这种写法: println!("upstream peer is: {:?}",upstream);

zjwztttt avatar Mar 04 '24 12:03 zjwztttt

May be you should pull last commit.

info!("upstream peer is: {:?}", upstream);

Tallone avatar Mar 04 '24 14:03 Tallone

The correct way to use debug format with variable name in the template string is

info!("upstream peer is: {upstream:?}");

foxwhite25 avatar Mar 05 '24 02:03 foxwhite25

Thanks to google translate that I could understand the issuer's concern. But is there a norm where there is a certain language to be followed for global understanding?

ambi88dex avatar Mar 05 '24 15:03 ambi88dex

This issue was totally my fault. The code in the quick-start guide isn't checked directly, but maybe it could converted to a doc test. It has been fixed now in the main branch, so this issue should be resolved.

johnhurt avatar Mar 13 '24 13:03 johnhurt