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.
35 lines
751 B
35 lines
751 B
package conf |
|
|
|
import ( |
|
"encoding/json" |
|
"time" |
|
) |
|
|
|
// StringDuration is a duration that is unmarshaled from a string. |
|
// Durations are normally unmarshaled from numbers. |
|
type StringDuration time.Duration |
|
|
|
// MarshalJSON implements json.Marshaler. |
|
func (d StringDuration) MarshalJSON() ([]byte, error) { |
|
return json.Marshal(time.Duration(d).String()) |
|
} |
|
|
|
// UnmarshalJSON implements json.Unmarshaler. |
|
func (d *StringDuration) UnmarshalJSON(b []byte) error { |
|
var in string |
|
if err := json.Unmarshal(b, &in); err != nil { |
|
return err |
|
} |
|
|
|
du, err := time.ParseDuration(in) |
|
if err != nil { |
|
return err |
|
} |
|
*d = StringDuration(du) |
|
|
|
return nil |
|
} |
|
|
|
func (d *StringDuration) unmarshalEnv(s string) error { |
|
return d.UnmarshalJSON([]byte(`"` + s + `"`)) |
|
}
|
|
|