mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-30 11:35:40 +00:00
Refactor endpoint in started interface
This commit is contained in:
@@ -63,8 +63,8 @@ func runWorker() error {
|
||||
}
|
||||
defer listener.Close()
|
||||
server := grpc.NewServer(
|
||||
grpc.ChainUnaryInterceptor(unaryLocaleInterceptor),
|
||||
grpc.ChainStreamInterceptor(streamLocaleInterceptor),
|
||||
grpc.ChainUnaryInterceptor(daemon.UnaryLocaleInterceptor),
|
||||
grpc.ChainStreamInterceptor(daemon.StreamLocaleInterceptor),
|
||||
)
|
||||
RegisterApplicationServiceServer(server, &applicationService{
|
||||
startedService: daemon.NewStartedService(daemon.ServiceOptions{Context: include.Context(context.Background())}),
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
|
||||
"github.com/sagernet/sing-box/experimental/locale"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
func setLocaleFromContext(ctx context.Context) {
|
||||
requestMetadata, loaded := metadata.FromIncomingContext(ctx)
|
||||
if !loaded {
|
||||
return
|
||||
}
|
||||
slices.ContainsFunc(requestMetadata.Get("accept-language"), locale.Set)
|
||||
}
|
||||
|
||||
func unaryLocaleInterceptor(ctx context.Context, request any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
|
||||
setLocaleFromContext(ctx)
|
||||
return handler(ctx, request)
|
||||
}
|
||||
|
||||
func streamLocaleInterceptor(server any, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
|
||||
setLocaleFromContext(stream.Context())
|
||||
return handler(server, stream)
|
||||
}
|
||||
@@ -66,8 +66,8 @@ func newDaemon() (*Daemon, error) {
|
||||
})
|
||||
authorizer := newAuthorizer(d)
|
||||
serverOptions := []grpc.ServerOption{
|
||||
grpc.ChainUnaryInterceptor(newUnaryAuthorizeInterceptor(authorizer), unaryLocaleInterceptor),
|
||||
grpc.ChainStreamInterceptor(newStreamAuthorizeInterceptor(authorizer), streamLocaleInterceptor),
|
||||
grpc.ChainUnaryInterceptor(newUnaryAuthorizeInterceptor(authorizer), daemon.UnaryLocaleInterceptor),
|
||||
grpc.ChainStreamInterceptor(newStreamAuthorizeInterceptor(authorizer), daemon.StreamLocaleInterceptor),
|
||||
}
|
||||
platformOptions, err := platformServerOptions(d)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user