allow to set any message as error
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
13
options.go
13
options.go
@@ -2,6 +2,7 @@ package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/unistack-org/micro/v3/server"
|
||||
@@ -12,6 +13,18 @@ type rspCodeVal struct {
|
||||
code int
|
||||
}
|
||||
|
||||
func SetError(err interface{}) error {
|
||||
return &Error{err: err}
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
err interface{}
|
||||
}
|
||||
|
||||
func (err *Error) Error() string {
|
||||
return fmt.Sprintf("%v", err.err)
|
||||
}
|
||||
|
||||
// SetRspCode saves response code in context, must be used by handler to specify http code
|
||||
func SetRspCode(ctx context.Context, code int) {
|
||||
if rsp, ok := ctx.Value(rspCodeKey{}).(*rspCodeVal); ok {
|
||||
|
||||
Reference in New Issue
Block a user