From e92ae8dd12d9fefc8a0c694cd6f12335c96a0c09 Mon Sep 17 00:00:00 2001 From: Kai-Chu Chung Date: Tue, 17 Apr 2018 11:00:35 +0800 Subject: [PATCH] feat(gerr): expose Code/Message getter (#6) use getter insteal of access by array first item --- gerr.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/gerr.go b/gerr.go index 919bef1..53b89cb 100644 --- a/gerr.go +++ b/gerr.go @@ -25,8 +25,22 @@ func (c *GErrors) AppendDomain(domain string) *GErrors { return c } -func (c GErrors) Empty() bool { - return len(c) == 0 +func (c *GErrors) Empty() bool { + return len(*c) == 0 +} + +func (c *GErrors) Code() uint { + if c.Empty() { + return 0 + } + return (*c)[0].Code +} + +func (c *GErrors) Message() string { + if c.Empty() { + return "" + } + return (*c)[0].Message } func NewGErrors() *GErrors { return &GErrors{} }