trpc.group/trpc-go/trpc-go@v1.0.3/pool/multiplexed/get_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 multiplexed 15 16 // GetOptions get conn configuration. 17 type GetOptions struct { 18 FP FrameParser 19 VID uint32 20 21 CACertFile string // CA certificate. 22 TLSCertFile string // Client certificate. 23 TLSKeyFile string // Client secret key. 24 TLSServerName string // The client verifies the server's service name, 25 // if not filled in, it defaults to the http hostname. 26 27 LocalAddr string 28 29 network string 30 address string 31 isStream bool 32 nodeKey string 33 } 34 35 // NewGetOptions creates GetOptions. 36 func NewGetOptions() GetOptions { 37 return GetOptions{} 38 } 39 40 // WithFrameParser sets the FrameParser of a single Get. 41 func (o *GetOptions) WithFrameParser(fp FrameParser) { 42 o.FP = fp 43 } 44 45 // WithDialTLS returns an Option which sets the client to support TLS. 46 func (o *GetOptions) WithDialTLS(certFile, keyFile, caFile, serverName string) { 47 o.TLSCertFile = certFile 48 o.TLSKeyFile = keyFile 49 o.CACertFile = caFile 50 o.TLSServerName = serverName 51 } 52 53 // WithVID returns an Option which sets virtual connection ID. 54 func (o *GetOptions) WithVID(vid uint32) { 55 o.VID = vid 56 } 57 58 // WithLocalAddr returns an Option which sets the local address when 59 // establishing a connection, and it is randomly selected by default 60 // when there are multiple network cards. 61 func (o *GetOptions) WithLocalAddr(addr string) { 62 o.LocalAddr = addr 63 } 64 65 func (o *GetOptions) update(network, address string) error { 66 if o.FP == nil { 67 return ErrFrameParserNil 68 } 69 isStream, err := isStream(network) 70 if err != nil { 71 return err 72 } 73 o.isStream = isStream 74 o.address = address 75 o.network = network 76 o.nodeKey = makeNodeKey(o.network, o.address) 77 return nil 78 }