mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 14:54:22 +01:00
lsps0: check service impl satisfies handler type.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -234,6 +235,16 @@ func sendError(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) RegisterService(desc *ServiceDesc, impl interface{}) {
|
func (s *Server) RegisterService(desc *ServiceDesc, impl interface{}) {
|
||||||
|
if impl == nil {
|
||||||
|
log.Fatalf("lsps0: Server.RegisterService got nil service implementation")
|
||||||
|
}
|
||||||
|
|
||||||
|
ht := reflect.TypeOf(desc.HandlerType).Elem()
|
||||||
|
st := reflect.TypeOf(impl)
|
||||||
|
if !st.Implements(ht) {
|
||||||
|
log.Fatalf("lsps0: Server.RegisterService found the handler of type %v that does not satisfy %v", st, ht)
|
||||||
|
}
|
||||||
|
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
log.Printf("RegisterService(%q)", desc.ServiceName)
|
log.Printf("RegisterService(%q)", desc.ServiceName)
|
||||||
|
|||||||
Reference in New Issue
Block a user