blob: 2a33be612fd1f319c8c46cbd480865d5564b189d [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package protocol
// Result is a RPC result
type Result interface {
// SetError sets error.
SetError(error)
// Error gets error.
Error() error
// SetResult sets invoker result.
SetResult(interface{})
// Result gets invoker result.
Result() interface{}
// SetAttachments replaces the existing attachments with the specified param.
SetAttachments(map[string]string)
// Attachments gets all attachments
Attachments() map[string]string
// AddAttachment adds the specified map to existing attachments in this instance.
AddAttachment(string, string)
// Attachment gets attachment by key with default value.
Attachment(string, string) string
}
/////////////////////////////
// Result Implement of RPC
/////////////////////////////
// RPCResult is default RPC result.
type RPCResult struct {
Attrs map[string]string
Err error
Rest interface{}
}
// SetError sets error.
func (r *RPCResult) SetError(err error) {
r.Err = err
}
// Error gets error.
func (r *RPCResult) Error() error {
return r.Err
}
// SetResult sets invoker result.
func (r *RPCResult) SetResult(rest interface{}) {
r.Rest = rest
}
// Result gets invoker result.
func (r *RPCResult) Result() interface{} {
return r.Rest
}
// SetAttachments replaces the existing attachments with the specified param.
func (r *RPCResult) SetAttachments(attr map[string]string) {
r.Attrs = attr
}
// Attachments gets all attachments
func (r *RPCResult) Attachments() map[string]string {
return r.Attrs
}
// AddAttachment adds the specified map to existing attachments in this instance.
func (r *RPCResult) AddAttachment(key, value string) {
r.Attrs[key] = value
}
// Attachment gets attachment by key with default value.
func (r *RPCResult) Attachment(key, defaultValue string) string {
v, ok := r.Attrs[key]
if !ok {
v = defaultValue
}
return v
}