Skip to content
Discussion options

You must be logged in to vote

Wait I'm confused. You example already runs two servers on different ports...

To answer what appears to be your real question:

Srv is an ordinary struct so you can do

pub struct Srv { db_pool: DatabasePool }

// and then create it with
.add_service(UserServiceServer::new(srv::Srv { db_pool }))

// and use it like any other struct field
async fn get_user(
    &self,
    _request: Request<GetUserRequest>,
) -> Result<Response<User>, tonic::Status> {
    // access the pool
    self.db_pool.do_something();

    // ...
}

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@itmecho
Comment options

@itmecho
Comment options

@davidpdrsn
Comment options

@davidpdrsn
Comment options

@itmecho
Comment options

Answer selected by itmecho
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants