The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Reid

go 有没有好的方式处理嵌套的切片

  •  
  •   Reid · Apr 14, 2022 · 2567 views
    This topic created in 1514 days ago, the information mentioned may be changed or developed.

    在查看 redis slowlog 时查询出来的时 interface{}, 实际是个嵌套的切片, 断言起来非常麻烦。如下: 前三个元素时 int , 后面一个元素又是个切片,不能很好一次性的转类型,现在有没有处理的第三方包,或者其他什么较好的方法处理这种情况? [[3411585 1649892418 215157 ["del" "somekey"]...]

    9 replies    2022-04-15 09:13:21 +08:00
    HiShan
        1
    HiShan  
       Apr 14, 2022
    反射 + 递归 ?
    yleoer
        2
    yleoer  
       Apr 14, 2022   ❤️ 1
    wellsc
        3
    wellsc  
       Apr 14, 2022
    @HiShan 就变成了屎山
    yleoer
        4
    yleoer  
       Apr 14, 2022
    Reid
        5
    Reid  
    OP
       Apr 14, 2022
    @HiShan
    @yleoer
    @wellsc
    收到,感谢
    hzzhzzdogee
        6
    hzzhzzdogee  
       Apr 14, 2022
    反射+递归 正解
    rrfeng
        7
    rrfeng  
       Apr 14, 2022
    它是固定格式啊,断言就够了。又不会出现某个位置类型突变的情况。
    HiShan
        8
    HiShan  
       Apr 14, 2022
    @wellsc 为啥?
    joesonw
        9
    joesonw  
       Apr 15, 2022 via iPhone
    返回[]interface{}是因为可能有空值,你直接 redis-cli 试试就知道了。返回[]interface{}的命令是有可能中间有 nil 的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1133 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 18:09 · PVG 02:09 · LAX 11:09 · JFK 14:09
    ♥ Do have faith in what you're doing.