snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
26
internal/proxyproto/raw.go
Normal file
26
internal/proxyproto/raw.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package proxyproto
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Raw type used by Centrifugo as type for fields in structs which value
|
||||
// we want to left untouched.
|
||||
type Raw []byte
|
||||
|
||||
// MarshalJSON returns *r as the JSON encoding of r.
|
||||
func (r Raw) MarshalJSON() ([]byte, error) {
|
||||
if r == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON sets *r to a copy of data.
|
||||
func (r *Raw) UnmarshalJSON(data []byte) error {
|
||||
if r == nil {
|
||||
return errors.New("raw: UnmarshalJSON on nil pointer")
|
||||
}
|
||||
*r = append((*r)[0:0], data...)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user