mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 14:54:22 +01:00
lsps0: lsps0 server implementation
This commit is contained in:
55
lsps0/protocol_server.go
Normal file
55
lsps0/protocol_server.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package lsps0
|
||||
|
||||
import "context"
|
||||
|
||||
type ProtocolServer interface {
|
||||
ListProtocols(
|
||||
ctx context.Context,
|
||||
req *ListProtocolsRequest,
|
||||
) (*ListProtocolsResponse, error)
|
||||
}
|
||||
type protocolServer struct {
|
||||
protocols []uint32
|
||||
}
|
||||
|
||||
type ListProtocolsRequest struct{}
|
||||
type ListProtocolsResponse struct {
|
||||
Protocols []uint32 `json:"protocols"`
|
||||
}
|
||||
|
||||
func NewProtocolServer(supportedProtocols []uint32) ProtocolServer {
|
||||
return &protocolServer{
|
||||
protocols: supportedProtocols,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *protocolServer) ListProtocols(
|
||||
ctx context.Context,
|
||||
req *ListProtocolsRequest,
|
||||
) (*ListProtocolsResponse, error) {
|
||||
return &ListProtocolsResponse{
|
||||
Protocols: s.protocols,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func RegisterProtocolServer(s ServiceRegistrar, p ProtocolServer) {
|
||||
s.RegisterService(
|
||||
&ServiceDesc{
|
||||
ServiceName: "lsps0",
|
||||
HandlerType: (*ProtocolServer)(nil),
|
||||
Methods: []MethodDesc{
|
||||
{
|
||||
MethodName: "lsps0.list_protocols",
|
||||
Handler: func(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) {
|
||||
in := new(ListProtocolsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return srv.(ProtocolServer).ListProtocols(ctx, in)
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
p,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user