GetFileDescriptorSet fetches the complete file descriptor set from BSR. This is used for the protojson resolver when marshaling to JSON. Returns linker.Files which has an AsResolver() method for protojson.
(ctx context.Context, messageName, commit string)
| 140 | // This is used for the protojson resolver when marshaling to JSON. |
| 141 | // Returns linker.Files which has an AsResolver() method for protojson. |
| 142 | func (c *Client) GetFileDescriptorSet(ctx context.Context, messageName, commit string) (linker.Files, error) { |
| 143 | if messageName == "" { |
| 144 | return nil, errors.New("message name is empty") |
| 145 | } |
| 146 | if commit == "" { |
| 147 | return nil, errors.New("commit is empty") |
| 148 | } |
| 149 | |
| 150 | key := cacheKey{messageName: messageName, commit: commit} |
| 151 | |
| 152 | // Use cache.Get which handles cache lookup and only calls the function on cache miss |
| 153 | entry, err, _ := c.cache.Get(key.String(), func() (*bsrCacheEntry, error) { |
| 154 | // This function is only called on cache miss |
| 155 | files, desc, fetchErr := c.fetchFromBSR(ctx, messageName, commit) |
| 156 | if fetchErr != nil { |
| 157 | return nil, fetchErr |
| 158 | } |
| 159 | return &bsrCacheEntry{files: files, messageDesc: desc}, nil |
| 160 | }) |
| 161 | |
| 162 | if err != nil { |
| 163 | return nil, err |
| 164 | } |
| 165 | return entry.files, nil |
| 166 | } |
| 167 | |
| 168 | // fetchFromBSR fetches the file descriptor set from BSR via the Connect API. |
| 169 | func (c *Client) fetchFromBSR(ctx context.Context, messageName, commit string) (linker.Files, protoreflect.MessageDescriptor, error) { |
nothing calls this directly
no test coverage detected