mediamtx/internal/conf/string_size.go
Alessandro Ros 9c6ba7e2c7
New authentication system (#1341) (#1992) (#2205) (#3081)
This is a new authentication system that covers all the features exposed by the server, including playback, API, metrics and PPROF, improves internal authentication by adding permissions, improves HTTP-based authentication by adding the ability to exclude certain actions from being authenticated, adds an additional method (JWT-based authentication).
2024-03-04 14:20:34 +01:00

37 lines
752 B
Go

package conf
import (
"encoding/json"
"code.cloudfoundry.org/bytefmt"
)
// StringSize is a size that is unmarshaled from a string.
type StringSize uint64
// MarshalJSON implements json.Marshaler.
func (s StringSize) MarshalJSON() ([]byte, error) {
return []byte(`"` + bytefmt.ByteSize(uint64(s)) + `"`), nil
}
// UnmarshalJSON implements json.Unmarshaler.
func (s *StringSize) UnmarshalJSON(b []byte) error {
var in string
if err := json.Unmarshal(b, &in); err != nil {
return err
}
v, err := bytefmt.ToBytes(in)
if err != nil {
return err
}
*s = StringSize(v)
return nil
}
// UnmarshalEnv implements env.Unmarshaler.
func (s *StringSize) UnmarshalEnv(_ string, v string) error {
return s.UnmarshalJSON([]byte(`"` + v + `"`))
}