github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/framework/qdrmanagement/entities/address.go (about)

     1  package entities
     2  
     3  import (
     4  	"encoding/json"
     5  	"strconv"
     6  	"strings"
     7  )
     8  
     9  // Address represents a Dispatch Router address
    10  type Address struct {
    11  	EntityCommon
    12  	Prefix         string           `json:"prefix"`
    13  	Pattern        string           `json:"pattern"`
    14  	Distribution   DistributionType `json:"distribution,string"`
    15  	Waypoint       bool             `json:"waypoint"`
    16  	IngressPhase   int              `json:"ingressPhase"`
    17  	EgressPhase    int              `json:"egressPhase"`
    18  	Priority       int              `json:"priority"`
    19  	EnableFallback bool             `json:"enableFallback"`
    20  }
    21  
    22  func (Address) GetEntityId() string {
    23  	return "router.config.address"
    24  }
    25  
    26  type DistributionType int
    27  
    28  const (
    29  	DistributionMulticast DistributionType = iota
    30  	DistributionClosest
    31  	DistributionBalanced
    32  	DistributionUnavailable
    33  )
    34  
    35  // Unmarshal JSON return the appropriate DistributionType for parsed string
    36  func (d *DistributionType) UnmarshalJSON(b []byte) error {
    37  	var s string
    38  
    39  	if len(b) == 0 {
    40  		return nil
    41  	}
    42  
    43  	if b[0] != '"' {
    44  		b = []byte(strconv.Quote(string(b)))
    45  	}
    46  	if err := json.Unmarshal(b, &s); err != nil {
    47  		return err
    48  	}
    49  	switch strings.ToLower(s) {
    50  	case "multicast":
    51  		*d = DistributionMulticast
    52  	case "closest":
    53  		*d = DistributionClosest
    54  	case "balanced":
    55  		*d = DistributionBalanced
    56  	case "unavailable":
    57  		*d = DistributionUnavailable
    58  	}
    59  	return nil
    60  
    61  }
    62  
    63  // MarshalJSON returns the string represenation of DistributionType
    64  func (d DistributionType) MarshalJSON() ([]byte, error) {
    65  	var s string
    66  	switch d {
    67  	case DistributionMulticast:
    68  		s = "multicast"
    69  	case DistributionClosest:
    70  		s = "closest"
    71  	case DistributionBalanced:
    72  		s = "balanced"
    73  	case DistributionUnavailable:
    74  		s = "unavailable"
    75  	}
    76  	return json.Marshal(s)
    77  }