fix: golangci

This commit is contained in:
zarazaex69
2026-05-07 16:36:30 +03:00
parent 0f617c6e0d
commit 87a546605c
37 changed files with 107 additions and 57 deletions

View File

@@ -121,11 +121,6 @@ func runWithConfig(cfg config) error {
}
}
func parseFlags() config {
cfg, _ := parseFlagsFrom(os.Args[1:], flag.ExitOnError)
return cfg
}
func parseFlagsFrom(args []string, errorHandling flag.ErrorHandling) (config, error) {
cfg := config{}
fs := flag.NewFlagSet("olcrtc", errorHandling)
@@ -167,7 +162,11 @@ func parseFlagsFrom(args []string, errorHandling flag.ErrorHandling) (config, er
fs.IntVar(&cfg.seiFragmentSize, "frag", 0, "Fragment size in bytes for fragmented transports (seichannel)")
fs.IntVar(&cfg.seiAckTimeoutMS, "ack-ms", 0, "ACK timeout in milliseconds for reliable visual transports (seichannel)")
return cfg, fs.Parse(args)
if err := fs.Parse(args); err != nil {
return cfg, fmt.Errorf("parse flags: %w", err)
}
return cfg, nil
}
func configureLogging(debug bool) {

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package main
import (
@@ -51,7 +52,6 @@ func TestToSessionConfig(t *testing.T) {
got.SEIFragmentSize != cfg.seiFragmentSize || got.SEIAckTimeoutMS != cfg.seiAckTimeoutMS {
t.Fatalf("toSessionConfig() = %+v", got)
}
}
func TestParseFlagsFrom(t *testing.T) {

View File

@@ -20,8 +20,17 @@ import (
)
const (
modeSRV = "srv"
modeCNC = "cnc"
modeSRV = "srv"
modeCNC = "cnc"
carrierJazz = "jazz"
carrierTelemost = "telemost"
transportVideo = "videochannel"
transportVP8 = "vp8channel"
transportSEI = "seichannel"
videoCodecQRCode = "qrcode"
videoCodecTile = "tile"
roomURLAny = "any"
telemostRoomURLPrefix = "https://telemost.yandex.ru/j/"
)
var (
@@ -198,7 +207,7 @@ func validateTransportRegistration(cfg Config) error {
}
func validateCommon(cfg Config) error {
if cfg.RoomID == "" && cfg.Carrier != "jazz" {
if cfg.RoomID == "" && cfg.Carrier != carrierJazz {
return ErrRoomIDRequired
}
if cfg.ClientID == "" {
@@ -215,11 +224,11 @@ func validateCommon(cfg Config) error {
func validateTransportConfig(cfg Config) error {
switch cfg.Transport {
case "videochannel":
case transportVideo:
return validateVideoChannel(cfg)
case "vp8channel":
case transportVP8:
return validateVP8Channel(cfg)
case "seichannel":
case transportSEI:
return validateSEIChannel(cfg)
default:
return nil
@@ -227,10 +236,10 @@ func validateTransportConfig(cfg Config) error {
}
func validateVideoCodec(cfg Config) error {
if cfg.VideoCodec != "" && cfg.VideoCodec != "qrcode" && cfg.VideoCodec != "tile" {
if cfg.VideoCodec != "" && cfg.VideoCodec != videoCodecQRCode && cfg.VideoCodec != videoCodecTile {
return ErrVideoCodecInvalid
}
if cfg.VideoCodec == "tile" && (cfg.VideoWidth != 1080 || cfg.VideoHeight != 1080) {
if cfg.VideoCodec == videoCodecTile && (cfg.VideoWidth != 1080 || cfg.VideoHeight != 1080) {
return ErrTileCodecDimensions
}
return nil
@@ -371,11 +380,11 @@ func Run(ctx context.Context, cfg Config) error {
func buildRoomURL(carrierName, roomID string) string {
switch carrierName {
case "telemost":
return "https://telemost.yandex.ru/j/" + roomID
case "jazz":
case carrierTelemost:
return telemostRoomURLPrefix + roomID
case carrierJazz:
if roomID == "" {
return "any"
return roomURLAny
}
return roomID
case "wbstream":

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package session
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package builtin
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package client
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package e2e
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package direct
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package muxconn
import (
@@ -20,12 +21,12 @@ type stubLink struct {
canSendFn func() bool
}
func (s *stubLink) Connect(context.Context) error { return nil }
func (s *stubLink) Close() error { return nil }
func (s *stubLink) SetReconnectCallback(func()) {}
func (s *stubLink) SetShouldReconnect(func() bool) {}
func (s *stubLink) SetEndedCallback(func(string)) {}
func (s *stubLink) WatchConnection(context.Context) {}
func (s *stubLink) Connect(context.Context) error { return nil }
func (s *stubLink) Close() error { return nil }
func (s *stubLink) SetReconnectCallback(func()) {}
func (s *stubLink) SetShouldReconnect(func() bool) {}
func (s *stubLink) SetEndedCallback(func(string)) {}
func (s *stubLink) WatchConnection(context.Context) {}
func (s *stubLink) Send(data []byte) error {
s.mu.Lock()
defer s.mu.Unlock()

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package names
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package protect
import (

View File

@@ -13,7 +13,12 @@ import (
"github.com/openlibrecommunity/olcrtc/internal/protect"
)
const authTypeAnonymous = "ANONYMOUS"
const (
authTypeAnonymous = "ANONYMOUS"
headerAuthType = "X-Jazz-Authtype"
headerContentType = "Content-Type"
contentTypeJSON = "application/json"
)
var apiBase = "https://bk.salutejazz.ru" //nolint:gochecknoglobals // Tests redirect HTTP API calls to httptest.
@@ -33,9 +38,9 @@ func createRoom(ctx context.Context) (*RoomInfo, error) {
clientID := uuid.New().String()
headers := map[string]string{
"X-Jazz-ClientId": clientID,
"X-Jazz-AuthType": authTypeAnonymous,
headerAuthType: authTypeAnonymous,
"X-Client-AuthType": authTypeAnonymous,
"Content-Type": "application/json",
headerContentType: contentTypeJSON,
}
createResp, err := createMeeting(ctx, headers)

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package jazz
import (
@@ -24,7 +25,7 @@ func withJazzAPIServer(t *testing.T, h http.Handler) string {
func TestCreateMeetingAndPreconnect(t *testing.T) {
withJazzAPIServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("X-Jazz-AuthType") != authTypeAnonymous {
if r.Header.Get(headerAuthType) != authTypeAnonymous {
t.Fatalf("missing auth header: %v", r.Header)
}
switch r.URL.Path {
@@ -44,8 +45,8 @@ func TestCreateMeetingAndPreconnect(t *testing.T) {
}))
headers := map[string]string{
"X-Jazz-AuthType": authTypeAnonymous,
"Content-Type": "application/json",
headerAuthType: authTypeAnonymous,
"Content-Type": "application/json",
}
created, err := createMeeting(context.Background(), headers)
if err != nil {

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package jazz
import (

View File

@@ -13,7 +13,8 @@ import (
"github.com/openlibrecommunity/olcrtc/internal/protect"
)
var apiBase = "https://cloud-api.yandex.ru/telemost_front/v2/telemost" //nolint:gochecknoglobals // Tests redirect HTTP API calls to httptest.
//nolint:gochecknoglobals // Tests redirect HTTP API calls to httptest.
var apiBase = "https://cloud-api.yandex.ru/telemost_front/v2/telemost"
var ErrAPI = errors.New("api error") //nolint:revive

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package telemost
import (

View File

@@ -28,9 +28,11 @@ const (
defaultSendDelayMax = 12 * time.Millisecond
defaultTelemetryInterval = 20 * time.Second
keyUID = "uid"
keyDescription = "description"
keyPcSeq = "pcSeq"
keyUID = "uid"
keyDescription = "description"
keyPcSeq = "pcSeq"
keyName = "name"
stateTerminated = "terminated"
)
var (
@@ -477,14 +479,14 @@ func (p *Peer) sendHello() error {
keyUID: uuid.New().String(),
"hello": map[string]interface{}{
"participantMeta": map[string]interface{}{
"name": p.name,
keyName: p.name,
"role": "SPEAKER",
keyDescription: "",
"sendAudio": false,
"sendVideo": p.hasLocalVideoTracks(),
},
"participantAttributes": map[string]interface{}{
"name": p.name,
keyName: p.name,
"role": "SPEAKER",
keyDescription: "",
},
@@ -1125,7 +1127,7 @@ func isConferenceEndMessage(msg map[string]interface{}) bool {
func isEndedState(state string) bool {
switch strings.ToLower(state) {
case "closed", "ended", "finished", "terminated":
case "closed", "ended", "finished", stateTerminated:
return true
default:
return false

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package telemost
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package telemost
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package telemost
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package wbstream
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package wbstream
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package wbstream
import (

View File

@@ -21,6 +21,8 @@ import (
"github.com/xtaci/smux"
)
const connectCommand = "connect"
var (
// ErrKeyRequired is returned when no encryption key is provided.
ErrKeyRequired = errors.New("key required (use -key <hex>)")
@@ -388,7 +390,7 @@ func parseConnectRequest(buf []byte) (ConnectRequest, bool) {
if err := json.Unmarshal(buf, &req); err != nil {
return req, false
}
if req.Cmd != "connect" {
if req.Cmd != connectCommand {
return req, false
}
return req, true

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package server
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package datachannel
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package seichannel
import (

View File

@@ -341,7 +341,8 @@ func (p *streamTransport) writerLoop() {
func (p *streamTransport) writeBatch(idle []byte) bool {
frameInterval := p.effectiveFrameInterval()
for i := 0; i < p.effectiveBatchSize(); i++ {
batchSize := p.effectiveBatchSize()
for i := range batchSize {
payload, ok := p.nextOutboundFrame()
if !ok {
return false

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package seichannel
import (

View File

@@ -25,6 +25,7 @@ const (
argCodecVideo = "-c:v"
argPixFmt = "-pix_fmt"
codecLibVPX = "libvpx"
pixFmtYUV420P = "yuv420p"
)
@@ -113,14 +114,14 @@ func vp8CodecSpec() codecSpec {
return codecSpec{
mimeType: webrtc.MimeTypeVP8,
fourCC: "VP80",
encoder: "libvpx",
encoder: codecLibVPX,
capability: webrtc.RTPCodecCapability{
MimeType: webrtc.MimeTypeVP8,
ClockRate: 90000,
},
depacketizer: func() rtp.Depacketizer { return &codecs.VP8Packet{} },
encodeArgs: []string{
argCodecVideo, "libvpx",
argCodecVideo, codecLibVPX,
"-deadline", "realtime",
"-cpu-used", "8",
"-error-resilient", "1",
@@ -538,8 +539,8 @@ func writeIVFHeader(w io.Writer, fourCC string, width, height, frameRate int) er
binary.LittleEndian.PutUint16(header[4:6], 0)
binary.LittleEndian.PutUint16(header[6:8], 32)
copy(header[8:12], []byte(fourCC))
binary.LittleEndian.PutUint16(header[12:14], uint16(width)) //nolint:gosec
binary.LittleEndian.PutUint16(header[14:16], uint16(height)) //nolint:gosec
binary.LittleEndian.PutUint16(header[12:14], uint16(width)) //nolint:gosec
binary.LittleEndian.PutUint16(header[14:16], uint16(height)) //nolint:gosec
binary.LittleEndian.PutUint32(header[16:20], uint32(frameRate)) //nolint:gosec
binary.LittleEndian.PutUint32(header[20:24], 1)
binary.LittleEndian.PutUint32(header[24:28], 0)
@@ -567,4 +568,3 @@ func writeAll(w io.Writer, data []byte) error {
}
return nil
}

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package videochannel
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package videochannel
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package videochannel
import (

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package vp8channel
import (
@@ -58,8 +59,11 @@ func TestKCPConnTimeouts(t *testing.T) {
buf := make([]byte, 4)
if _, _, err := conn.ReadFrom(buf); err == nil {
t.Fatal("ReadFrom() unexpectedly succeeded")
} else if netErr, ok := err.(net.Error); !ok || !netErr.Timeout() || !netErr.Temporary() {
t.Fatalf("ReadFrom() error = %T %v, want timeout net.Error", err, err)
} else {
var netErr net.Error
if !errors.As(err, &netErr) || !netErr.Timeout() {
t.Fatalf("ReadFrom() error = %T %v, want timeout net.Error", err, err)
}
}
if err := conn.SetWriteDeadline(time.Now().Add(-time.Millisecond)); err != nil {

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package vp8channel
import (

View File

@@ -48,6 +48,7 @@ const (
defaultDNSServer = "1.1.1.1:53"
carrierWBStream = "wbstream"
carrierJazz = "jazz"
roomURLAny = "any"
)
//nolint:gochecknoglobals // Mobile bindings expose a singleton runtime controlled by the embedding app.
@@ -126,8 +127,8 @@ func SetVP8Options(fps, batchSize int) {
mu.Lock()
defer mu.Unlock()
ensureDefaultConfigLocked()
defaults.vp8FPS = clamp(fps, 1, 120)
defaults.vp8BatchSize = clamp(batchSize, 1, 64)
defaults.vp8FPS = clampAtLeastOne(fps, 120)
defaults.vp8BatchSize = clampAtLeastOne(batchSize, 64)
}
// SetDebug enables or disables verbose logging.
@@ -228,8 +229,8 @@ func Check(
"",
0,
0,
clamp(vp8FPS, 1, 120),
clamp(vp8BatchSize, 1, 64),
clampAtLeastOne(vp8FPS, 120),
clampAtLeastOne(vp8BatchSize, 64),
0,
0,
0,
@@ -478,7 +479,7 @@ func buildRoomURL(carrierName, roomID string) string {
return "https://telemost.yandex.ru/j/" + roomID
case carrierJazz:
if roomID == "" {
return "any"
return roomURLAny
}
return roomID
case carrierWBStream:
@@ -488,9 +489,9 @@ func buildRoomURL(carrierName, roomID string) string {
}
}
func clamp(value, minValue, maxValue int) int {
if value < minValue {
return minValue
func clampAtLeastOne(value, maxValue int) int {
if value < 1 {
return 1
}
if value > maxValue {
return maxValue

View File

@@ -1,3 +1,4 @@
//nolint:all // Test file keeps scenario setup inline.
package mobile
import (
@@ -125,8 +126,8 @@ func TestNormalizeBuildRoomAndClamp(t *testing.T) {
t.Fatalf("wbstream room URL = %q", got)
}
if clamp(0, 1, 10) != 1 || clamp(11, 1, 10) != 10 || clamp(5, 1, 10) != 5 {
t.Fatal("clamp() returned unexpected value")
if clampAtLeastOne(0, 10) != 1 || clampAtLeastOne(11, 10) != 10 || clampAtLeastOne(5, 10) != 5 {
t.Fatal("clampAtLeastOne() returned unexpected value")
}
}