Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up unused utils #819

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions livekit/types_test

This file was deleted.

2 changes: 1 addition & 1 deletion logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (l *zapLogger[T]) WithoutSampler() Logger {
func (l *zapLogger[T]) WithDeferredValues() (Logger, DeferredFieldResolver) {
dup := *l
def, resolve := zaputil.NewDeferrer()
dup.deferred = append(dup.deferred[0:len(dup.deferred):len(dup.deferred)], def)
dup.deferred = append(dup.deferred, def)
dup.zap = dup.ToZap()
return &dup, resolve
}
Expand Down
4 changes: 2 additions & 2 deletions logger/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func ToSlogHandler(log Logger) slog.Handler {

type slogDiscard struct{}

func (_ slogDiscard) Enabled(ctx context.Context, level slog.Level) bool {
func (slogDiscard) Enabled(ctx context.Context, level slog.Level) bool {
return false
}

func (_ slogDiscard) Handle(ctx context.Context, record slog.Record) error {
func (slogDiscard) Handle(ctx context.Context, record slog.Record) error {
return nil
}

Expand Down
15 changes: 3 additions & 12 deletions rpc/typed_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/utils/must"
"github.com/livekit/protocol/utils/options"
"github.com/livekit/psrpc"
"github.com/livekit/psrpc/pkg/middleware"
)
Expand Down Expand Up @@ -84,26 +83,18 @@ func (p *ClientParams) Options() []psrpc.ClientOption {
}

func (p *ClientParams) Args() (psrpc.MessageBus, psrpc.ClientOption) {
return p.Bus, WithClientOptions(p.Options()...)
}

func WithClientOptions(opts ...psrpc.ClientOption) psrpc.ClientOption {
return func(o *psrpc.ClientOpts) { options.Apply(o, opts) }
}

func WithServerOptions(opts ...psrpc.ServerOption) psrpc.ServerOption {
return func(o *psrpc.ServerOpts) { options.Apply(o, opts) }
return p.Bus, psrpc.WithClientOptions(p.Options()...)
}

func WithServerObservability(logger logger.Logger) psrpc.ServerOption {
return WithServerOptions(
return psrpc.WithServerOptions(
middleware.WithServerMetrics(PSRPCMetricsObserver{}),
WithServerLogger(logger),
)
}

func WithDefaultServerOptions(psrpcConfig PSRPCConfig, logger logger.Logger) psrpc.ServerOption {
return WithServerOptions(
return psrpc.WithServerOptions(
psrpc.WithServerChannelSize(psrpcConfig.BufferSize),
WithServerObservability(logger),
)
Expand Down
144 changes: 0 additions & 144 deletions utils/messaging.go

This file was deleted.

22 changes: 0 additions & 22 deletions utils/must.go

This file was deleted.

10 changes: 10 additions & 0 deletions utils/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ func Apply[T any, F ~func(T)](o T, opts []F) T {
}
return o
}

func Make[T any, F ~func(*T)](opts []F) T {
var o T
Apply(&o, opts)
return o
}

func New[T any, F ~func(*T)](opts []F) *T {
return Apply(new(T), opts)
}
2 changes: 1 addition & 1 deletion utils/protoproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (p *ProtoProxy[T]) Updated() <-chan struct{} {
func (p *ProtoProxy[T]) Get() T {
p.lock.RLock()
defer p.lock.RUnlock()
return proto.Clone(p.message).(T)
return CloneProto(p.message)
}

func (p *ProtoProxy[T]) Stop() {
Expand Down
Loading