Hello everybody!
I want to use some pre-defined objects inside stream handler. For example, i want to save users data, which i read from stream inside stream handler:
func handler (s Stream) {
data := s.read()
// here I want to use initialized db instanse to save data: db.Put(key, data)
// but I dont understand how to get access to this db
}
How can this be implemented in libp2p?
I don’t know what is your specific use case, but I’ll suggest using this pattern:
func handler_factory(dbInstance *DB) func(network.Stream) {
return func(s network.Stream) {
data := s.read()
}
}
1 Like