-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmiddleware.go
25 lines (22 loc) · 1.02 KB
/
middleware.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Package gosocketify is a package with server side implementation for socketify.
// It provides utilities and middlewares to handle connections and messages.
package gosocketify
import (
"log"
)
// Middleware type definition.
// A function that takes a connection and a message as input and returns a new message.
// This function is meant to be used as a pipeline to transform or modify the messages
// before they are processed by the server.
type MiddlewareFunc func(Connection, Message) Message
// LoggingMiddleware logs data received and the connection id.
//
// This middleware is useful for debugging and monitoring purposes.
// It prints the connection id and the received message to the console.
//
// The message returned is the original message, so you can use this middleware
// in any position in your pipeline without affecting the original message.
func LoggingMiddleware(conn Connection, message Message) Message {
log.Printf("Received message from %s: %v", conn.ID, message)
return message
}