@@ -24,7 +24,9 @@ package driver
2424
2525import (
2626 "context"
27+ "encoding/json"
2728 "path"
29+ "reflect"
2830)
2931
3032// newCluster creates a new Cluster implementation.
@@ -221,3 +223,151 @@ func (c *cluster) RemoveServer(ctx context.Context, serverID ServerID) error {
221223 }
222224 return nil
223225}
226+
227+ // replicationFactor represents the replication factor of a collection
228+ // Has special value ReplicationFactorSatellite for satellite collections
229+ type replicationFactor int
230+
231+ type inventoryCollectionParametersInternal struct {
232+ Deleted bool `json:"deleted,omitempty"`
233+ DoCompact bool `json:"doCompact,omitempty"`
234+ ID string `json:"id,omitempty"`
235+ IndexBuckets int `json:"indexBuckets,omitempty"`
236+ Indexes []InventoryIndex `json:"indexes,omitempty"`
237+ IsSmart bool `json:"isSmart,omitempty"`
238+ SmartGraphAttribute string `json:"smartGraphAttribute,omitempty"`
239+ IsSystem bool `json:"isSystem,omitempty"`
240+ IsVolatile bool `json:"isVolatile,omitempty"`
241+ JournalSize int64 `json:"journalSize,omitempty"`
242+ KeyOptions struct {
243+ Type string `json:"type,omitempty"`
244+ AllowUserKeys bool `json:"allowUserKeys,omitempty"`
245+ LastValue int64 `json:"lastValue,omitempty"`
246+ } `json:"keyOptions"`
247+ Name string `json:"name,omitempty"`
248+ NumberOfShards int `json:"numberOfShards,omitempty"`
249+ Path string `json:"path,omitempty"`
250+ PlanID string `json:"planId,omitempty"`
251+ ReplicationFactor replicationFactor `json:"replicationFactor,omitempty"`
252+ ShardKeys []string `json:"shardKeys,omitempty"`
253+ Shards map [ShardID ][]ServerID `json:"shards,omitempty"`
254+ Status CollectionStatus `json:"status,omitempty"`
255+ Type CollectionType `json:"type,omitempty"`
256+ WaitForSync bool `json:"waitForSync,omitempty"`
257+ DistributeShardsLike string `json:"distributeShardsLike,omitempty"`
258+ }
259+
260+ func (p * InventoryCollectionParameters ) asInternal () inventoryCollectionParametersInternal {
261+ return inventoryCollectionParametersInternal {
262+ Deleted : p .Deleted ,
263+ DoCompact : p .DoCompact ,
264+ ID : p .ID ,
265+ IndexBuckets : p .IndexBuckets ,
266+ Indexes : p .Indexes ,
267+ IsSmart : p .IsSmart ,
268+ SmartGraphAttribute : p .SmartGraphAttribute ,
269+ IsSystem : p .IsSystem ,
270+ IsVolatile : p .IsVolatile ,
271+ JournalSize : p .JournalSize ,
272+ KeyOptions : p .KeyOptions ,
273+ Name : p .Name ,
274+ NumberOfShards : p .NumberOfShards ,
275+ Path : p .Path ,
276+ PlanID : p .PlanID ,
277+ ReplicationFactor : replicationFactor (p .ReplicationFactor ),
278+ ShardKeys : p .ShardKeys ,
279+ Shards : p .Shards ,
280+ Status : p .Status ,
281+ Type : p .Type ,
282+ WaitForSync : p .WaitForSync ,
283+ DistributeShardsLike : p .DistributeShardsLike ,
284+ }
285+ }
286+
287+ func (p * InventoryCollectionParameters ) fromInternal (i inventoryCollectionParametersInternal ) {
288+ * p = i .asExternal ()
289+ }
290+
291+ func (p * inventoryCollectionParametersInternal ) asExternal () InventoryCollectionParameters {
292+ return InventoryCollectionParameters {
293+ Deleted : p .Deleted ,
294+ DoCompact : p .DoCompact ,
295+ ID : p .ID ,
296+ IndexBuckets : p .IndexBuckets ,
297+ Indexes : p .Indexes ,
298+ IsSmart : p .IsSmart ,
299+ SmartGraphAttribute : p .SmartGraphAttribute ,
300+ IsSystem : p .IsSystem ,
301+ IsVolatile : p .IsVolatile ,
302+ JournalSize : p .JournalSize ,
303+ KeyOptions : p .KeyOptions ,
304+ Name : p .Name ,
305+ NumberOfShards : p .NumberOfShards ,
306+ Path : p .Path ,
307+ PlanID : p .PlanID ,
308+ ReplicationFactor : int (p .ReplicationFactor ),
309+ ShardKeys : p .ShardKeys ,
310+ Shards : p .Shards ,
311+ Status : p .Status ,
312+ Type : p .Type ,
313+ WaitForSync : p .WaitForSync ,
314+ DistributeShardsLike : p .DistributeShardsLike ,
315+ }
316+ }
317+
318+ // MarshalJSON converts InventoryCollectionParameters into json
319+ func (p * InventoryCollectionParameters ) MarshalJSON () ([]byte , error ) {
320+ return json .Marshal (p .asInternal ())
321+ }
322+
323+ // UnmarshalJSON loads InventoryCollectionParameters from json
324+ func (p * InventoryCollectionParameters ) UnmarshalJSON (d []byte ) error {
325+ var internal inventoryCollectionParametersInternal
326+ if err := json .Unmarshal (d , & internal ); err != nil {
327+ return err
328+ }
329+
330+ p .fromInternal (internal )
331+ return nil
332+ }
333+
334+ const (
335+ replicationFactorSatelliteString string = "satellite"
336+ )
337+
338+ // MarshalJSON marshals InventoryCollectionParameters to arangodb json representation
339+ func (r replicationFactor ) MarshalJSON () ([]byte , error ) {
340+ var replicationFactor interface {}
341+
342+ if int (r ) == ReplicationFactorSatellite {
343+ replicationFactor = replicationFactorSatelliteString
344+ } else {
345+ replicationFactor = int (r )
346+ }
347+
348+ return json .Marshal (replicationFactor )
349+ }
350+
351+ // UnmarshalJSON marshals InventoryCollectionParameters to arangodb json representation
352+ func (r * replicationFactor ) UnmarshalJSON (d []byte ) error {
353+ var internal interface {}
354+
355+ if err := json .Unmarshal (d , & internal ); err != nil {
356+ return err
357+ }
358+
359+ if i , ok := internal .(float64 ); ok {
360+ * r = replicationFactor (i )
361+ return nil
362+ } else if str , ok := internal .(string ); ok {
363+ if ok && str == replicationFactorSatelliteString {
364+ * r = replicationFactor (ReplicationFactorSatellite )
365+ return nil
366+ }
367+ }
368+
369+ return & json.UnmarshalTypeError {
370+ Value : string (d ),
371+ Type : reflect .TypeOf (r ).Elem (),
372+ }
373+ }
0 commit comments