github.com/alloyzeus/go-azfl@v0.0.0-20231220071816-9740126a2d07/azcore/service_method.go (about)

     1  package azcore
     2  
     3  //region ServiceMethodError
     4  
     5  // ServiceMethodError is a specialization of ServiceError which focuses
     6  // on method-related errors.
     7  type ServiceMethodError interface {
     8  	ServiceError
     9  
    10  	AZServiceMethodError()
    11  }
    12  
    13  // ServiceMethodErrorMsg is a basic implementation of ServiceMethodError
    14  // which provides an error message string.
    15  type ServiceMethodErrorMsg struct {
    16  	msg string
    17  }
    18  
    19  var _ ServiceMethodError = ServiceMethodErrorMsg{}
    20  
    21  // AZServiceMethodError is required for conformance with ServiceMethodError.
    22  func (ServiceMethodErrorMsg) AZServiceMethodError() {}
    23  
    24  // AZServiceError is required for conformance with ServiceError.
    25  func (ServiceMethodErrorMsg) AZServiceError() {}
    26  
    27  func (err ServiceMethodErrorMsg) Error() string { return err.msg }
    28  
    29  // ServiceMethodInternalError represents error in the method, service, or in
    30  // any dependency required to achieve the objective.
    31  //
    32  // This is analogous to HTTP's 5xx status code.
    33  type ServiceMethodInternalError interface {
    34  	ServiceMethodError
    35  
    36  	AZServiceMethodInternalError()
    37  }
    38  
    39  // ServiceMethodInternalErrorMsg is a basic implementation of
    40  // ServiceMethodInternalError which provides error message string.
    41  type ServiceMethodInternalErrorMsg struct {
    42  	msg string
    43  }
    44  
    45  var _ ServiceMethodInternalError = ServiceMethodInternalErrorMsg{}
    46  
    47  // AZServiceMethodInternalError is required for conformance
    48  // with ServiceMethodInternalError.
    49  func (ServiceMethodInternalErrorMsg) AZServiceMethodInternalError() {}
    50  
    51  // AZServiceMethodError is required for conformance with ServiceMethodError.
    52  func (ServiceMethodInternalErrorMsg) AZServiceMethodError() {}
    53  
    54  // AZServiceError is required for conformance with ServiceError.
    55  func (ServiceMethodInternalErrorMsg) AZServiceError() {}
    56  
    57  func (err ServiceMethodInternalErrorMsg) Error() string { return err.msg }
    58  
    59  //endregion
    60  
    61  // ErrServiceMethodNotImplemented is usually used when a method is unable to
    62  // achieve its objective because some part of it is unimplemented.
    63  //
    64  // Analogous to HTTP's 501 status code and gRPC's 12 status code.
    65  var ErrServiceMethodNotImplemented = &ServiceMethodInternalErrorMsg{msg: "not implemented"}
    66  
    67  //region ServiceMethodContext
    68  
    69  // ServiceMethodContext is an abstraction for input and output contexts used
    70  // when calling a method.
    71  type ServiceMethodContext interface {
    72  	ServiceContext
    73  
    74  	AZServiceMethodContext()
    75  }
    76  
    77  //endregion
    78  
    79  //region ServiceMethodMessage
    80  
    81  // ServiceMethodMessage abstracts the messages, i.e., requests and responses.
    82  type ServiceMethodMessage interface {
    83  	AZServiceMethodMessage()
    84  
    85  	// ServiceMethodContext returns the context of this message.
    86  	//
    87  	// Implementations must return most specialized context implementation.
    88  	MethodContext() ServiceMethodContext
    89  }
    90  
    91  //endregion