github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/protocol/introduce/properties.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package introduce
     8  
     9  import "errors"
    10  
    11  const (
    12  	myDIDPropKey    = "myDID"
    13  	theirDIDPropKey = "theirDID"
    14  	piidPropKey     = "piid"
    15  	errorPropKey    = "error"
    16  )
    17  
    18  type eventProps struct {
    19  	myDID    string
    20  	theirDID string
    21  	piid     string
    22  	err      error
    23  }
    24  
    25  func newEventProps(md *metaData) *eventProps {
    26  	return &eventProps{
    27  		myDID:    md.MyDID,
    28  		theirDID: md.TheirDID,
    29  		piid:     md.PIID,
    30  		err:      md.err,
    31  	}
    32  }
    33  
    34  func (e *eventProps) MyDID() string {
    35  	return e.myDID
    36  }
    37  
    38  func (e *eventProps) TheirDID() string {
    39  	return e.theirDID
    40  }
    41  
    42  func (e *eventProps) PIID() string {
    43  	return e.piid
    44  }
    45  
    46  func (e eventProps) Err() error {
    47  	if errors.As(e.err, &customError{}) {
    48  		return nil
    49  	}
    50  
    51  	return e.err
    52  }
    53  
    54  // All implements EventProperties interface.
    55  func (e eventProps) All() map[string]interface{} {
    56  	all := map[string]interface{}{}
    57  	if e.myDID != "" {
    58  		all[myDIDPropKey] = e.myDID
    59  	}
    60  
    61  	if e.theirDID != "" {
    62  		all[theirDIDPropKey] = e.theirDID
    63  	}
    64  
    65  	if e.piid != "" {
    66  		all[piidPropKey] = e.piid
    67  	}
    68  
    69  	if e.Err() != nil {
    70  		all[errorPropKey] = e.Err()
    71  	}
    72  
    73  	return all
    74  }