mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-09-26 19:51:26 +08:00
modernize code (#4947)
This commit is contained in:
34
internal/conf/env/env_test.go
vendored
34
internal/conf/env/env_test.go
vendored
@@ -8,27 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func stringPtr(v string) *string {
|
||||
return &v
|
||||
}
|
||||
|
||||
func intPtr(v int) *int {
|
||||
return &v
|
||||
}
|
||||
|
||||
func uintPtr(v uint) *uint {
|
||||
return &v
|
||||
}
|
||||
|
||||
func boolPtr(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
||||
func float64Ptr(v float64) *float64 {
|
||||
return &v
|
||||
}
|
||||
|
||||
func durationPtr(v time.Duration) *time.Duration {
|
||||
func ptrOf[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
@@ -137,17 +117,17 @@ func TestLoad(t *testing.T) {
|
||||
|
||||
require.Equal(t, testStruct{
|
||||
MyString: "testcontent",
|
||||
MyStringOpt: stringPtr("testcontent2"),
|
||||
MyStringOpt: ptrOf("testcontent2"),
|
||||
MyInt: 123,
|
||||
MyIntOpt: intPtr(456),
|
||||
MyIntOpt: ptrOf(456),
|
||||
MyUint: 8910,
|
||||
MyUintOpt: uintPtr(112313),
|
||||
MyUintOpt: ptrOf(uint(112313)),
|
||||
MyFloat: 15.2,
|
||||
MyFloatOpt: float64Ptr(16.2),
|
||||
MyFloatOpt: ptrOf(16.2),
|
||||
MyBool: true,
|
||||
MyBoolOpt: boolPtr(false),
|
||||
MyBoolOpt: ptrOf(false),
|
||||
MyDuration: 22000000000,
|
||||
MyDurationOpt: (*myDuration)(durationPtr(30000000000)),
|
||||
MyDurationOpt: ptrOf(myDuration(30000000000)),
|
||||
MyMap: map[string]*mapEntry{
|
||||
"mykey": {
|
||||
MyValue: "",
|
||||
|
@@ -13,8 +13,8 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func timePtr(t time.Time) *time.Time {
|
||||
return &t
|
||||
func ptrOf[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
type dummyPathManager struct{}
|
||||
@@ -31,7 +31,7 @@ func (dummyPathManager) APIPathsList() (*defs.APIPathList, error) {
|
||||
ID: "123324354",
|
||||
},
|
||||
Ready: true,
|
||||
ReadyTime: timePtr(time.Date(2003, 11, 4, 23, 15, 7, 0, time.UTC)),
|
||||
ReadyTime: ptrOf(time.Date(2003, 11, 4, 23, 15, 7, 0, time.UTC)),
|
||||
Tracks: []string{"H264", "H265"},
|
||||
BytesReceived: 123,
|
||||
BytesSent: 456,
|
||||
|
@@ -28,7 +28,7 @@ var errNoSupportedCodecsFrom = errors.New(
|
||||
"the stream doesn't contain any supported codec, which are currently " +
|
||||
"AV1, VP9, VP8, H265, H264, Opus, G722, G711, LPCM")
|
||||
|
||||
func uint16Ptr(v uint16) *uint16 {
|
||||
func ptrOf[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ func setupVideoTrack(
|
||||
encoder := &rtpvp9.Encoder{
|
||||
PayloadType: 96,
|
||||
PayloadMaxSize: webrtcPayloadMaxSize,
|
||||
InitialPictureID: uint16Ptr(8445),
|
||||
InitialPictureID: ptrOf(uint16(8445)),
|
||||
}
|
||||
err := encoder.Init()
|
||||
if err != nil {
|
||||
|
@@ -7,11 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func uint16Ptr(v uint16) *uint16 {
|
||||
return &v
|
||||
}
|
||||
|
||||
func stringPtr(v string) *string {
|
||||
func ptrOf[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
@@ -176,8 +172,8 @@ var iceFragmentCases = []struct {
|
||||
"a=sendrecv\n",
|
||||
[]*webrtc.ICECandidateInit{{
|
||||
Candidate: "3628911098 1 udp 2130706431 192.168.3.218 49462 typ host",
|
||||
SDPMid: stringPtr("0"),
|
||||
SDPMLineIndex: uint16Ptr(0),
|
||||
SDPMid: ptrOf("0"),
|
||||
SDPMLineIndex: ptrOf(uint16(0)),
|
||||
}},
|
||||
"a=ice-ufrag:tUQMzoQAVLzlvBys\r\n" +
|
||||
"a=ice-pwd:pimyGfJcjjRwvUjnmGOODSjtIxyDljQj\r\n" +
|
||||
|
@@ -20,7 +20,7 @@ const (
|
||||
recreatePause = 10 * time.Second
|
||||
)
|
||||
|
||||
func int64Ptr(v int64) *int64 {
|
||||
func ptrOf[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func (m *muxer) initialize() {
|
||||
m.ctx = ctx
|
||||
m.ctxCancel = ctxCancel
|
||||
m.created = time.Now()
|
||||
m.lastRequestTime = int64Ptr(time.Now().UnixNano())
|
||||
m.lastRequestTime = ptrOf(time.Now().UnixNano())
|
||||
m.bytesSent = new(uint64)
|
||||
m.chGetInstance = make(chan muxerGetInstanceReq)
|
||||
|
||||
|
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func uint16Ptr(v uint16) *uint16 {
|
||||
func ptrOf[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
@@ -682,7 +682,7 @@ func TestServerPatchNotFound(t *testing.T) {
|
||||
|
||||
frag, err := whip.ICEFragmentMarshal(offer.SDP, []*pwebrtc.ICECandidateInit{{
|
||||
Candidate: "mycandidate",
|
||||
SDPMLineIndex: uint16Ptr(0),
|
||||
SDPMLineIndex: ptrOf(uint16(0)),
|
||||
}})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
Reference in New Issue
Block a user