15 lines
440 B
Go
15 lines
440 B
Go
package syncsocket
|
|||
|
|
|
||
|
|
// syncScalar keeps a client-supplied sync value to what sync state holds: null, a number or a
|
||
|
|
// bounded string. Objects, arrays and booleans are refused so arbitrary JSON is never stored as
|
||
|
|
// shared session state.
|
||
|
|
func syncScalar(value any) (any, bool) {
|
||
|
|
switch typed := value.(type) {
|
||
|
|
case nil, float64:
|
||
|
|
return typed, true
|
||
|
|
case string:
|
||
|
|
return boundedSyncString(typed), true
|
||
|
|
default:
|
||
|
|
return nil, false
|
||
|
|
}
|
||
|
|
}
|