golanggohlsrtmpwebrtcmedia-serverobs-studiortcprtmp-proxyrtmp-serverrtprtsprtsp-proxyrtsp-relayrtsp-serversrtstreamingwebrtc-proxy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
package conf |
|
|
|
import ( |
|
"encoding/json" |
|
"fmt" |
|
) |
|
|
|
// AuthAction is an authentication action. |
|
type AuthAction string |
|
|
|
// auth actions |
|
const ( |
|
AuthActionPublish AuthAction = "publish" |
|
AuthActionRead AuthAction = "read" |
|
AuthActionPlayback AuthAction = "playback" |
|
AuthActionAPI AuthAction = "api" |
|
AuthActionMetrics AuthAction = "metrics" |
|
AuthActionPprof AuthAction = "pprof" |
|
) |
|
|
|
// MarshalJSON implements json.Marshaler. |
|
func (d AuthAction) MarshalJSON() ([]byte, error) { |
|
return json.Marshal(string(d)) |
|
} |
|
|
|
// UnmarshalJSON implements json.Unmarshaler. |
|
func (d *AuthAction) UnmarshalJSON(b []byte) error { |
|
var in string |
|
if err := json.Unmarshal(b, &in); err != nil { |
|
return err |
|
} |
|
|
|
switch in { |
|
case string(AuthActionPublish), |
|
string(AuthActionRead), |
|
string(AuthActionPlayback), |
|
string(AuthActionAPI), |
|
string(AuthActionMetrics), |
|
string(AuthActionPprof): |
|
*d = AuthAction(in) |
|
|
|
default: |
|
return fmt.Errorf("invalid auth action: '%s'", in) |
|
} |
|
|
|
return nil |
|
} |
|
|
|
// UnmarshalEnv implements env.Unmarshaler. |
|
func (d *AuthAction) UnmarshalEnv(_ string, v string) error { |
|
return d.UnmarshalJSON([]byte(`"` + v + `"`)) |
|
}
|
|
|