github.com/onosproject/onos-api/go@v0.10.32/onos/config/v3/types.go (about)

     1  // SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package v3
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/google/uuid"
    11  	types "github.com/onosproject/onos-api/go/onos/config"
    12  
    13  	"strings"
    14  )
    15  
    16  const separator = ":"
    17  
    18  // ID is an identifier type
    19  type ID string
    20  
    21  // Index is the index of an object
    22  type Index uint64
    23  
    24  // Ordinal is a configuration ordinal
    25  type Ordinal uint64
    26  
    27  // Revision is a revision number
    28  type Revision uint64
    29  
    30  // NewUUID generates a new uuid
    31  func NewUUID() uuid.UUID {
    32  	newUUID, err := uuid.NewUUID()
    33  	if err != nil {
    34  		newUUID = uuid.New()
    35  	}
    36  	return newUUID
    37  }
    38  
    39  // NodeID is a config node identifier
    40  type NodeID string
    41  
    42  // TargetID is a target ID
    43  type TargetID string
    44  
    45  // TargetType is a target type
    46  type TargetType string
    47  
    48  // TargetRole is a target role
    49  type TargetRole string
    50  
    51  // TargetVersion is a target version
    52  type TargetVersion string
    53  
    54  // TargetVersionedID is a versioned target ID
    55  type TargetVersionedID types.ID
    56  
    57  // MastershipTerm mastership term
    58  type MastershipTerm uint64
    59  
    60  // NewTargetVersionedID returns a new versioned target identifier
    61  func NewTargetVersionedID(id ID, version TargetVersion) TargetVersionedID {
    62  	return TargetVersionedID(fmt.Sprintf("%s%s%s", id, separator, version))
    63  }
    64  
    65  // GetID returns the target ID
    66  func (i TargetVersionedID) GetID() ID {
    67  	return ID(i[:strings.Index(string(i), separator)])
    68  }
    69  
    70  // GetVersion returns the target version
    71  func (i TargetVersionedID) GetVersion() TargetVersion {
    72  	return TargetVersion(i[strings.Index(string(i), separator)+1:])
    73  }