mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-12 09:44:59 +00:00
9c6ba7e2c7
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).
65 lines
1.1 KiB
Go
65 lines
1.1 KiB
Go
package conf
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/bluenviron/mediamtx/internal/logger"
|
|
)
|
|
|
|
// LogLevel is the logLevel parameter.
|
|
type LogLevel logger.Level
|
|
|
|
// MarshalJSON implements json.Marshaler.
|
|
func (d LogLevel) MarshalJSON() ([]byte, error) {
|
|
var out string
|
|
|
|
switch d {
|
|
case LogLevel(logger.Error):
|
|
out = "error"
|
|
|
|
case LogLevel(logger.Warn):
|
|
out = "warn"
|
|
|
|
case LogLevel(logger.Info):
|
|
out = "info"
|
|
|
|
default:
|
|
out = "debug"
|
|
}
|
|
|
|
return json.Marshal(out)
|
|
}
|
|
|
|
// UnmarshalJSON implements json.Unmarshaler.
|
|
func (d *LogLevel) UnmarshalJSON(b []byte) error {
|
|
var in string
|
|
if err := json.Unmarshal(b, &in); err != nil {
|
|
return err
|
|
}
|
|
|
|
switch in {
|
|
case "error":
|
|
*d = LogLevel(logger.Error)
|
|
|
|
case "warn":
|
|
*d = LogLevel(logger.Warn)
|
|
|
|
case "info":
|
|
*d = LogLevel(logger.Info)
|
|
|
|
case "debug":
|
|
*d = LogLevel(logger.Debug)
|
|
|
|
default:
|
|
return fmt.Errorf("invalid log level: '%s'", in)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UnmarshalEnv implements env.Unmarshaler.
|
|
func (d *LogLevel) UnmarshalEnv(_ string, v string) error {
|
|
return d.UnmarshalJSON([]byte(`"` + v + `"`))
|
|
}
|