C++ golang操作函数中是否有一些方法,如C+中的std::bind+;?

C++ golang操作函数中是否有一些方法,如C+中的std::bind+;?,c++,go,C++,Go,这是我的设计: type Handler func(c *gin.Context) func PreExecute(c *gin.Context, handle_func Handler) Handler { if c.User.IsAuthorized { return handle_func } else { return some_error_handle_func } } 我想通过预执行来装饰每个处理程序,就像Python中的装饰

这是我的设计:

type Handler func(c *gin.Context)
func PreExecute(c *gin.Context, handle_func Handler) Handler {
    if c.User.IsAuthorized {
        return handle_func
    } else {
        return some_error_handle_func
    }
}
我想通过预执行来装饰每个处理程序,就像Python中的装饰一样。所以我在golang中寻找一些std::bind函数,以获得与Handler完全相同的预执行签名

我所期望的是:

handler = std::bind(PreExecute, _1, handler) // where _1 hold the position for parameter `c *gin.Context`
一些函数,如std::bind


在Golang我怎么做?有没有更优雅的方法来完成这项工作?

结束语,以下是我的解决方案:

handler_new = func(c *gin.Context){ return PreExecute(c, handler_old)(c) } // since there is no return value of handler, so just do not use `return` statements, I will not correct this error
然后,handler_new可以用作:

handler_new(some_context)
这和

handler_new = std::bind(PreExecute, _1, handler_old)

在C++

中,请不要向标签发送垃圾邮件。只使用与您的问题相关的标记。@ChristianDean实际上我受到了aop或装饰概念的启发,所以我认为这不是垃圾邮件标记。也许有人对这个问题感兴趣