@@ -76,15 +76,18 @@ func NewServer[C, Q, M, R any](opts ServerOptions[C, Q, M, R]) (*Server[C, Q, M,
7676 return nil
7777 }
7878
79- var cfg C
79+ var (
80+ cfg C
81+ protocolInfo = ProtocolInfo {Version : message .Header .Version }
82+ )
8083 err := opts .Codec .Decode (message .Body , & cfg )
8184 if err != nil {
8285 m := createErrorMessage (err , message .Header , MessageStatusErrDecodeFailed )
8386 d .SendMessage (m )
8487 return nil
8588 }
8689
87- if err := opts .Init (cfg ); err != nil {
90+ if err := opts .Init (cfg , protocolInfo ); err != nil {
8891 m := createErrorMessage (err , message .Header , MessageStatusErrInitServerFailed )
8992 d .SendMessage (m )
9093 return nil
@@ -259,12 +262,20 @@ func createErrorMessage(err error, h Header, failureStatus uint16) Message {
259262 return m
260263}
261264
265+ // ProtocolInfo is the protocol information passed to the server's Init function.
266+ type ProtocolInfo struct {
267+ // The version passed down from the client.
268+ // This usually represents a major version,
269+ // so any increment should be considered a breaking change.
270+ Version uint16 `json:"version"`
271+ }
272+
262273// ServerOptions is the options for a server.
263274type ServerOptions [C , Q , M , R any ] struct {
264275 // Init is the function that will be called when the server is started.
265276 // It can be used to initialize the server with the given configuration.
266277 // If an error is returned, the server will stop.
267- Init func (C ) error
278+ Init func (C , ProtocolInfo ) error
268279
269280 // Handle is the function that will be called when a request is received.
270281 Handle func (* Call [Q , M , R ])
0 commit comments