Summary - Extract proxy bootstrap implementation from bootstrap.go into internal/bootstrap/proxy.go, keeping only the Bootstrap interface in the shared file. This prepares for origin/edge servers to have their own bootstrap implementations. - Rename NewBootstrap() → NewProxyBootstrap() to follow the explicit factory naming convention. - Rebrand signature from SRSProxy to SRSX and update logger context key accordingly. - Add srs-develop skill with task router, module routing workflow, proxy unit test script, and RTMP E2E test script. - Remove st-develop skill (superseded by srs-develop). - Add srs-support eval #21 for HLS AnnexB decode error scenario. Test plan - go build ./cmd/proxy/... compiles successfully - go test ./cmd/... ./internal/... passes - E2E RTMP proxy test (proxy-e2e-test.sh) passes - Verify proxy starts and logs SRSX-Proxy/<version> started --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
// Copyright (c) 2025 Winlin
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
package logger
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
)
|
|
|
|
type key string
|
|
|
|
var cidKey key = "cid.srsx.ossrs.org"
|
|
|
|
// generateContextID generates a random context id in string.
|
|
func GenerateContextID() string {
|
|
randomBytes := make([]byte, 32)
|
|
_, _ = rand.Read(randomBytes)
|
|
hash := sha256.Sum256(randomBytes)
|
|
hashString := hex.EncodeToString(hash[:])
|
|
cid := hashString[:7]
|
|
return cid
|
|
}
|
|
|
|
// WithContext creates a new context with cid, which will be used for log.
|
|
func WithContext(ctx context.Context) context.Context {
|
|
return WithContextID(ctx, GenerateContextID())
|
|
}
|
|
|
|
// WithContextID creates a new context with cid, which will be used for log.
|
|
func WithContextID(ctx context.Context, cid string) context.Context {
|
|
return context.WithValue(ctx, cidKey, cid)
|
|
}
|
|
|
|
// ContextID returns the cid in context, or empty string if not set.
|
|
func ContextID(ctx context.Context) string {
|
|
if cid, ok := ctx.Value(cidKey).(string); ok {
|
|
return cid
|
|
}
|
|
return ""
|
|
}
|