I'm trying to do something in Go, similar to C++'s bind.
In C++ :
class A {
public:
typedef std::function<bool(const string&)> Handler;
bool func(A::Handler& handler) {
// getData will get data from file at path
auto data = getData(path);
return handler(data);
}
};
In another class B:
Class B {
public:
bool run() {
using namespace std::placeholders;
A::Handler handler = bind(&B::read, this, _1);
m_A.initialize();
return m_A.func(handler);
}
bool read(const string& data) {
std::out << data << std::endl;
}
private:
A m_A {};
};
when B's run() function is called, it will bind class B member function read with A's Handler.
Then m_A.func(hander)
is called, it will call getData()
. The data got is then parsed to B::read(const string& data)
Is there any way to do it in Go? How to create a forwarding call wrapper in golang?