snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
31
internal/config/format.go
Normal file
31
internal/config/format.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/centrifugal/centrifugo/v6/internal/configtypes"
|
||||
"github.com/centrifugal/centrifugo/v6/internal/tools"
|
||||
)
|
||||
|
||||
// ValidatePublicationData validates publication data according to the specified format.
|
||||
// Returns an error if the data doesn't match the format requirements.
|
||||
func ValidatePublicationData(data []byte, format string) error {
|
||||
switch format {
|
||||
case configtypes.PublicationDataFormatJSON:
|
||||
if !tools.IsValidJSON(data) {
|
||||
return errors.New("data is not valid JSON")
|
||||
}
|
||||
case configtypes.PublicationDataFormatJSONObject:
|
||||
if !tools.IsValidJSONObject(data) {
|
||||
return errors.New("data is not valid JSON object")
|
||||
}
|
||||
case configtypes.PublicationDataFormatBinary:
|
||||
// Binary format allows empty data, no validation needed
|
||||
default:
|
||||
// Default behavior: reject empty data
|
||||
if len(data) == 0 {
|
||||
return errors.New("data required")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user