gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/go-control-plane/pkg/server/stream/v3/stream.go (about) 1 package stream 2 3 import ( 4 "gitee.com/ks-custle/core-gm/grpc" 5 6 discovery "gitee.com/ks-custle/core-gm/go-control-plane/envoy/service/discovery/v3" 7 ) 8 9 // Stream Generic RPC stream. 10 type Stream interface { 11 grpc.ServerStream 12 13 Send(*discovery.DiscoveryResponse) error 14 Recv() (*discovery.DiscoveryRequest, error) 15 } 16 17 type DeltaStream interface { 18 grpc.ServerStream 19 20 Send(*discovery.DeltaDiscoveryResponse) error 21 Recv() (*discovery.DeltaDiscoveryRequest, error) 22 } 23 24 // StreamState will keep track of resource state per type on a stream. 25 // 26 //goland:noinspection GoNameStartsWithPackageName 27 type StreamState struct { // nolint:golint,revive 28 // Indicates whether the original DeltaRequest was a wildcard LDS/RDS request. 29 wildcard bool 30 31 // ResourceVersions contains a hash of the resource as the value and the resource name as the key. 32 // This field stores the last state sent to the client. 33 resourceVersions map[string]string 34 35 // indicates whether the object has beed modified since its creation 36 first bool 37 } 38 39 func (s *StreamState) GetResourceVersions() map[string]string { 40 return s.resourceVersions 41 } 42 43 func (s *StreamState) SetResourceVersions(resourceVersions map[string]string) { 44 s.first = false 45 s.resourceVersions = resourceVersions 46 } 47 48 func (s *StreamState) IsFirst() bool { 49 return s.first 50 } 51 52 func (s *StreamState) IsWildcard() bool { 53 return s.wildcard 54 } 55 56 // NewStreamState initializes a stream state. 57 func NewStreamState(wildcard bool, initialResourceVersions map[string]string) StreamState { 58 state := StreamState{ 59 wildcard: wildcard, 60 resourceVersions: initialResourceVersions, 61 first: true, 62 } 63 64 if initialResourceVersions == nil { 65 state.resourceVersions = make(map[string]string) 66 } 67 68 return state 69 }