github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/remote/response_status_code.go (about)

     1  package remote
     2  
     3  import "strconv"
     4  
     5  type ResponseStatusCode int32
     6  
     7  const (
     8  	ResponseStatusCodeOK ResponseStatusCode = iota
     9  	ResponseStatusCodeUNAVAILABLE
    10  	ResponseStatusCodeTIMEOUT
    11  	ResponseStatusCodePROCESSNAMEALREADYEXIST
    12  	ResponseStatusCodeERROR
    13  	ResponseStatusCodeDeadLetter
    14  	ResponseStatusCodeMAX // just a boundary.
    15  )
    16  
    17  var responseNames [ResponseStatusCodeMAX]string
    18  
    19  func init() {
    20  	responseNames[ResponseStatusCodeOK] = "ResponseStatusCodeOK"
    21  	responseNames[ResponseStatusCodeUNAVAILABLE] = "ResponseStatusCodeUNAVAILABLE"
    22  	responseNames[ResponseStatusCodeTIMEOUT] = "ResponseStatusCodeTIMEOUT"
    23  	responseNames[ResponseStatusCodePROCESSNAMEALREADYEXIST] = "ResponseStatusCodePROCESSNAMEALREADYEXIST"
    24  	responseNames[ResponseStatusCodePROCESSNAMEALREADYEXIST] = "ResponseStatusCodePROCESSNAMEALREADYEXIST"
    25  	responseNames[ResponseStatusCodeERROR] = "ResponseStatusCodeERROR"
    26  	responseNames[ResponseStatusCodeDeadLetter] = "ResponseStatusCodeDeadLetter"
    27  }
    28  
    29  func (c ResponseStatusCode) ToInt32() int32 {
    30  	return int32(c)
    31  }
    32  
    33  func (c ResponseStatusCode) String() string {
    34  	statusCode := int(c)
    35  	if statusCode < 0 || statusCode >= len(responseNames) {
    36  		return "ResponseStatusCode-" + strconv.Itoa(int(c))
    37  	}
    38  	return responseNames[statusCode]
    39  }
    40  
    41  func (c ResponseStatusCode) AsError() *ResponseError {
    42  	switch c {
    43  	case ResponseStatusCodeOK:
    44  		return nil
    45  	case ResponseStatusCodeUNAVAILABLE:
    46  		return ErrUnAvailable
    47  	case ResponseStatusCodeTIMEOUT:
    48  		return ErrTimeout
    49  	case ResponseStatusCodePROCESSNAMEALREADYEXIST:
    50  		return ErrProcessNameAlreadyExist
    51  	case ResponseStatusCodeERROR:
    52  		return ErrUnknownError
    53  	case ResponseStatusCodeDeadLetter:
    54  		return ErrDeadLetter
    55  	default:
    56  		return &ResponseError{c}
    57  	}
    58  }