github.com/onosproject/onos-api/go@v0.10.32/onos/config/v2/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 v2
     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  // Revision is a revision number
    25  type Revision uint64
    26  
    27  // NewUUID generates a new uuid
    28  func NewUUID() uuid.UUID {
    29  	newUUID, err := uuid.NewUUID()
    30  	if err != nil {
    31  		newUUID = uuid.New()
    32  	}
    33  	return newUUID
    34  }
    35  
    36  // ConfigurationID is a configuration identifier type
    37  type ConfigurationID string
    38  
    39  // ProposalID is a proposal identifier type
    40  type ProposalID string
    41  
    42  // TransactionID is a transaction identifier type
    43  type TransactionID string
    44  
    45  // TargetID is a target ID
    46  type TargetID string
    47  
    48  // TargetType is a target type
    49  type TargetType string
    50  
    51  // TargetRole is a target role
    52  type TargetRole string
    53  
    54  // TargetVersion is a target version
    55  type TargetVersion string
    56  
    57  // TargetVersionedID is a versioned target ID
    58  type TargetVersionedID types.ID
    59  
    60  // MastershipTerm mastership term
    61  type MastershipTerm uint64
    62  
    63  // NewTargetVersionedID returns a new versioned target identifier
    64  func NewTargetVersionedID(id ID, version TargetVersion) TargetVersionedID {
    65  	return TargetVersionedID(fmt.Sprintf("%s%s%s", id, separator, version))
    66  }
    67  
    68  // GetID returns the target ID
    69  func (i TargetVersionedID) GetID() ID {
    70  	return ID(i[:strings.Index(string(i), separator)])
    71  }
    72  
    73  // GetVersion returns the target version
    74  func (i TargetVersionedID) GetVersion() TargetVersion {
    75  	return TargetVersion(i[strings.Index(string(i), separator)+1:])
    76  }