You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/11/16 08:14:59 UTC

[GitHub] [dubbo-go] XiaoWeiKIN opened a new issue #1590: filter specifications suggest

XiaoWeiKIN opened a new issue #1590:
URL: https://github.com/apache/dubbo-go/issues/1590


   # Filter 编写规范
   
   注意:
   
   1. extension.get(xxx),为 lazy 初始化。
   2. extension.get(xxx),要保证单例。
   
   
   
   模板:
   
   ```go
   var (
   	once   sync.Once 
   	// 变量尽量简短有含义
   	active *activeFilter 
   )
   
   func init() {
       // extension.SetFilter() 必须 set 保证单例的私有化构造函数
       // 禁止直接 set 一个 func
   	extension.SetFilter(constant.ActiveFilterKey, newActiveFilter)
   }
   
   // filter struct 应该为私有化,所有filter获取必须通过 extension.get(),禁止外部实例化
   // filter 名称应当为: 他的作用 + Filter
   // 对于同时作用于 provider 和 consumser的应该命名为:他的作用 + side + Filter
   // 禁止直接命名为 Filter 这种毫无含义的结构体
   type activeFilter struct{}
   
   func newActiveFilter() filter.Filter {
   	if active == nil {
   	   // 虽然 extension.get(xx) 为 only read 但是建议增加once保护.
   		once.Do(func() {
   			active = &activeFilter{}
   		})
   	}
   	return active
   }
   
   ```
   
   1. extension.SetFilter() 必须 set 保证单例的私有化构造函数, **禁止直接 set 一个 func().**
   
      反例:没有保证单例
   
      ```go
      extension.SetFilter(constant.ActiveFilterKey, func() filter.Filter {
      		return &Filter{}
      	}))
      ```
      
   2.  **不推荐直接命名为 Filter 这种毫无含义的结构体**,Filter 名称应当为: 他的作用 + Filter。对于同时作用于 provider 和 consumser的应该命名为:他的作用 + side + Filter。
   
   3. **Filter struct 应该为私有化**,所有 Filter 获取必须通过 extension.get(),**禁止外部直接实例化 Filter。**
   
   4. 虽然 extension.get(xx) 为 only read 但是实例化时**建议增加 once 保护**.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] AlexStocks closed issue #1590: filter spec suggest

Posted by GitBox <gi...@apache.org>.
AlexStocks closed issue #1590:
URL: https://github.com/apache/dubbo-go/issues/1590


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo-go] XiaoWeiKIN commented on issue #1590: filter specifications suggest

Posted by GitBox <gi...@apache.org>.
XiaoWeiKIN commented on issue #1590:
URL: https://github.com/apache/dubbo-go/issues/1590#issuecomment-970013012


   ```go
   func (paf *ProviderAuthFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
   	logger.Infof("invoking providerAuth filter.")
   	url := invoker.GetURL()
   ```
   禁止在 filter.invoke 方法内,打印毫无意义的日志。如果要打印,建议设置为 debug。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org