Files
upstream-mirror b352a9a30d
Some checks failed
test / Lint (push) Failing after 3s
test / Test with Go 1.26.8 (push) Failing after 2s
snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:17:21 +05:00

32 lines
910 B
Go

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
}