You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/04/23 02:46:20 UTC

[GitHub] [apisix-dashboard] starsz commented on pull request #1812: fix: can not configure upstream with no nodes

starsz commented on pull request #1812:
URL: https://github.com/apache/apisix-dashboard/pull/1812#issuecomment-825347305


   > > @liuxiran
   > > How about we make it in the backend? Please see https://github.com/apache/apisix-dashboard/blob/master/api/internal/core/entity/format.go#L49, we can initialize the `nodes` as an empty slice instead of a nil one. Just change `var nodes []*Node` to `nodes := make([]*Node, 0)` .
   > > Looking forward to your insights.
   > 
   > @imjoey Thanks for your advice, and it really make sense for me.
   > 
   > before this change, when get info about an upstream with no nodes
   > fe will get
   > <img alt="WechatIMG5" width="834" src="https://user-images.githubusercontent.com/2561857/115748640-ee326980-a3c8-11eb-809a-e09e63cd6955.png">
   > 
   > actually `nodes:null` causes the problem
   > 
   > after this change, fe will get
   > <img alt="WechatIMG4" width="969" src="https://user-images.githubusercontent.com/2561857/115748817-1ae68100-a3c9-11eb-87c6-89c5c9dcd18f.png">
   > 
   > which is matches expectation.
   > 
   > BTW, I have a question in the process of debugging:
   > there are some logs I added to watch the changes of `upstream.Nodes` before the advice
   > <img alt="WechatIMG7" width="740" src="https://user-images.githubusercontent.com/2561857/115749803-11a9e400-a3ca-11eb-96cc-a6621465ab08.png">
   > I found even if I did not do this change, the `upstram.Nodes` will always be `[]`, but what Fe got is different, I haven't thought about it for a long time.
   > 
   > Also @nic-chen @Jaycean @starsz to take a look, thanks a lot
   
   Hi, @liuxiran 
   In golang, you should distinguish `nil slice` and `empty slice`
   
   ```
   var x []*entity.Node
   ```
   is a nil slice.
   
   ```
   y := make([]*entity.Node, 0)
   ```
   is an empty slice. The length and value are 0.
   If you use printf or println to print them, the result is both "[]".
   
   In this situation, because the upstream.Nodes' type is interface{}.So it's a little more complex.
   You can use 
   ```
   reflect.ValueOf(upstream.Nodes).IsNil()
   ```
   to see the true value.
   
   
   
   


-- 
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.

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