github.com/TrueCloudLab/frostfs-api-go/v2@v2.0.0-20230228134343-196241c4e79a/status/types.go (about)

     1  package status
     2  
     3  // Detail represents structure of NeoFS API V2-compatible status detail message.
     4  type Detail struct {
     5  	id uint32
     6  
     7  	val []byte
     8  }
     9  
    10  // ID returns identifier of the Detail.
    11  func (x *Detail) ID() uint32 {
    12  	if x != nil {
    13  		return x.id
    14  	}
    15  
    16  	return 0
    17  }
    18  
    19  // SetID sets identifier of the Detail.
    20  func (x *Detail) SetID(id uint32) {
    21  	x.id = id
    22  }
    23  
    24  // Value returns value of the Detail.
    25  func (x *Detail) Value() []byte {
    26  	if x != nil {
    27  		return x.val
    28  	}
    29  
    30  	return nil
    31  }
    32  
    33  // SetValue sets value of the Detail.
    34  func (x *Detail) SetValue(val []byte) {
    35  	x.val = val
    36  }
    37  
    38  // Code represents NeoFS API V2-compatible status code.
    39  type Code uint32
    40  
    41  // EqualNumber checks if the numerical Code equals num.
    42  func (x Code) EqualNumber(num uint32) bool {
    43  	return uint32(x) == num
    44  }
    45  
    46  // Status represents structure of NeoFS API V2-compatible status return message.
    47  type Status struct {
    48  	code Code
    49  
    50  	msg string
    51  
    52  	details []Detail
    53  }
    54  
    55  // Code returns code of the Status.
    56  func (x *Status) Code() Code {
    57  	if x != nil {
    58  		return x.code
    59  	}
    60  
    61  	return 0
    62  }
    63  
    64  // SetCode sets code of the Status.
    65  func (x *Status) SetCode(code Code) {
    66  	x.code = code
    67  }
    68  
    69  // Message sets message of the Status.
    70  func (x *Status) Message() string {
    71  	if x != nil {
    72  		return x.msg
    73  	}
    74  
    75  	return ""
    76  }
    77  
    78  // SetMessage sets message of the Status.
    79  func (x *Status) SetMessage(msg string) {
    80  	x.msg = msg
    81  }
    82  
    83  // NumberOfParameters returns number of network parameters.
    84  func (x *Status) NumberOfDetails() int {
    85  	if x != nil {
    86  		return len(x.details)
    87  	}
    88  
    89  	return 0
    90  }
    91  
    92  // IterateDetails iterates over details of the Status.
    93  // Breaks iteration on f's true return.
    94  //
    95  // Handler must not be nil.
    96  func (x *Status) IterateDetails(f func(*Detail) bool) {
    97  	if x != nil {
    98  		for i := range x.details {
    99  			if f(&x.details[i]) {
   100  				break
   101  			}
   102  		}
   103  	}
   104  }
   105  
   106  // ResetDetails empties the detail list.
   107  func (x *Status) ResetDetails() {
   108  	if x != nil {
   109  		x.details = x.details[:0]
   110  	}
   111  }
   112  
   113  // AppendDetails appends the list of details to the Status.
   114  func (x *Status) AppendDetails(ds ...Detail) {
   115  	if x != nil {
   116  		x.details = append(x.details, ds...)
   117  	}
   118  }
   119  
   120  // SetStatusDetails sets Detail list of the Status.
   121  func SetStatusDetails(dst *Status, ds []Detail) {
   122  	dst.ResetDetails()
   123  	dst.AppendDetails(ds...)
   124  }