V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
roy2220

自动生成 Go 的“代理类(struct)”

  •  
  •   roy2220 · Jun 16, 2020 · 2965 views
    This topic created in 2142 days ago, the information mentioned may be changed or developed.
    撸了个 Go 的“代理类”生成器,自动分析 struct 、interface 的所有方法(支持嵌套结构),生成一个 proxy struct,可以通过这个 proxy struct 拦截各种方法调用,修改调用参数、返回值等,需要自取 => https://github.com/roy2220/proxyz
    4 replies    2020-06-21 11:22:10 +08:00
    wfhtqp
        1
    wfhtqp  
       Jun 17, 2020
    画蛇添足
    cc100
        2
    cc100  
       Jun 17, 2020
    这个代理是为了解决什么问题呢
    roy2220
        3
    roy2220  
    OP
       Jun 17, 2020
    @cc100 常见就是 AOP 、mock 这类需求
    saber000
        4
    saber000  
       Jun 21, 2020
    可以给单元测试提供 spy 的机制吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2663 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 16:00 · PVG 00:00 · LAX 09:00 · JFK 12:00
    ♥ Do have faith in what you're doing.