github.com/profzone/eden-framework@v1.0.10/pkg/courier/transport_http/transform/err_msg_map.go (about)

     1  package transform
     2  
     3  import (
     4  	"sort"
     5  
     6  	"github.com/profzone/eden-framework/pkg/courier/status_error"
     7  )
     8  
     9  type ErrMsgMap map[string]string
    10  
    11  func (errMsgMap ErrMsgMap) Set(keyPath string, errMsg string) {
    12  	errMsgMap[keyPath] = errMsg
    13  }
    14  
    15  func (errMsgMap ErrMsgMap) Merge(otherErrMsgMap ErrMsgMap) ErrMsgMap {
    16  	if otherErrMsgMap == nil {
    17  		return errMsgMap
    18  	}
    19  	for field, msg := range otherErrMsgMap {
    20  		errMsgMap[field] = msg
    21  	}
    22  	return errMsgMap
    23  }
    24  
    25  func (errMsgMap ErrMsgMap) ErrorFieldsIn(in string, parentField string) (errFields status_error.ErrorFields) {
    26  	if len(errMsgMap) == 0 {
    27  		return
    28  	}
    29  
    30  	for field := range errMsgMap {
    31  		if parentField != "" {
    32  			field = parentField + "." + field
    33  		}
    34  		errFields = append(errFields, status_error.NewErrorField(in, field, errMsgMap[field]))
    35  	}
    36  
    37  	sort.Sort(errFields)
    38  	return
    39  }