github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/azid/id.go (about)

     1  package azid
     2  
     3  import (
     4  	"github.com/alloyzeus/go-azfl/azob"
     5  )
     6  
     7  // ID is abstract for entity IDs.
     8  //
     9  // In relation to ID-num, an ID is analogous to path in URL.
    10  //
    11  //     https://example.com/stores/12345/items/456789
    12  //
    13  // The part `/stores/12345/items/456789` is item's ID, and `456789`` is
    14  // the ID-num.
    15  //
    16  // An ID-num is always scoped, while an ID could be used to distinctively
    17  // identify an instance of an entity system-wide.
    18  //
    19  //     https://example.com/stores/StoreABC/items/456789
    20  //     https://example.com/stores/StoreXYZ/items/456789
    21  //
    22  // In above example, two items from two different stores have the same ID-num
    23  // but their respective IDs will not be the same. This system allows each
    24  // store to scale independently without significantly affecting each others.
    25  type ID[IDNumT IDNum] interface {
    26  	azob.Equatable
    27  
    28  	BinFieldMarshalable
    29  	BinMarshalable
    30  	TextMarshalable
    31  
    32  	// // Returns an array of the hosts' IDs.
    33  	// Hosts() []ID
    34  
    35  	// AZIDNum returns only the ID-num part of this ID.
    36  	AZIDNum() IDNumT
    37  }
    38  
    39  // IDFromString is a function which creates an instance of ID
    40  // from an input string.
    41  type IDFromString[IDNumT IDNum] func(idString string) (ID[IDNumT], Error)