Implement RPC
This commit is contained in:
parent
9699582d72
commit
496d5f412f
6 changed files with 289 additions and 0 deletions
27
rpc/response.go
Normal file
27
rpc/response.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
func (s *server) handleResponse(ctx context.Context, data []byte) {
|
||||
var response Response
|
||||
err := json.Unmarshal(data, &response)
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "Cannot Parse Response", "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
s.requestMutex.Lock()
|
||||
defer s.requestMutex.Unlock()
|
||||
r, ok := s.requests[response.ID]
|
||||
if !ok {
|
||||
slog.ErrorContext(ctx, "Unknown Response", "response", response)
|
||||
return
|
||||
}
|
||||
|
||||
// Send Response to Original Caller
|
||||
r <- &response
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue