trpc.group/trpc-go/trpc-go@v1.0.3/naming/loadbalance/options.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 package loadbalance 15 16 import ( 17 "context" 18 "time" 19 ) 20 21 // Options is the call options. 22 type Options struct { 23 Ctx context.Context // request context 24 Interval time.Duration // refresh interval 25 Namespace string // namespace 26 Key string // hash key 27 LoadBalanceType string // load balance type 28 Replicas int // virtual node coefficient of consistent hash 29 } 30 31 // Option modifies the Options. 32 type Option func(*Options) 33 34 // WithContext returns an Option which set request ctx. 35 func WithContext(ctx context.Context) Option { 36 return func(o *Options) { 37 o.Ctx = ctx 38 } 39 } 40 41 // WithNamespace returns an Option which set namespace. 42 func WithNamespace(namespace string) Option { 43 return func(opts *Options) { 44 opts.Namespace = namespace 45 } 46 } 47 48 // WithInterval returns an Option which set load balance refresh interval. 49 func WithInterval(interval time.Duration) Option { 50 return func(opts *Options) { 51 opts.Interval = interval 52 } 53 } 54 55 // WithKey returns an Option which set the hash key of status route. 56 func WithKey(k string) Option { 57 return func(o *Options) { 58 o.Key = k 59 } 60 } 61 62 // WithReplicas returns an Option which set the virtual node coefficient. 63 func WithReplicas(r int) Option { 64 return func(o *Options) { 65 o.Replicas = r 66 } 67 } 68 69 // WithLoadBalanceType returns an Option which set load balance type. 70 func WithLoadBalanceType(name string) Option { 71 return func(opts *Options) { 72 opts.LoadBalanceType = name 73 } 74 }