github.com/aaabigfish/gopkg@v1.1.0/ecode/message.go (about)

     1  package ecode
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  type Message struct {
     8  	ECode
     9  	EMsg string
    10  }
    11  
    12  // Error new message with code and msg
    13  func Error(code ECode, msg string) *Message {
    14  	return &Message{ECode: code, EMsg: msg}
    15  }
    16  
    17  // Errorf new message with code and msg
    18  func Errorf(code ECode, format string, args ...interface{}) *Message {
    19  	return Error(code, fmt.Sprintf(format, args...))
    20  }
    21  
    22  func (m *Message) String() string {
    23  	if m.EMsg == "" {
    24  		return m.ECode.String()
    25  	}
    26  	return fmt.Sprintf("%s:%s", m.ECode.String(), m.EMsg)
    27  }
    28  
    29  func (m *Message) Error() string {
    30  	return m.String()
    31  }