Documentation
¶
Index ¶
Constants ¶
View Source
const (
// JWTSecret defines default JWT secret
JWTSecret = "istioIsAwesome"
)
Variables ¶
View Source
var Authentication = func(r *http.Request) (model.User, error) { t, e := request.ParseFromRequest(r, request.OAuth2Extractor, func(token *jwt.Token) (interface{}, error) { b := []byte(JWTSecret) return b, nil }) if e != nil { return model.User{}, ErrJWTUnauthorized } username := t.Claims.(jwt.MapClaims)["username"].(string) u, ok := model.MockUsers[username] if !ok { return model.User{}, ErrJWTUnauthorized } return u, nil }
Authentication authenticates incoming request.
View Source
var BindFailFn = func(c *gin.Context, e error) { log.Info("[BindFailFn]", "err", e) c.JSON(http.StatusBadRequest, gin.H{ "code": 1, "data": e.Error(), }) }
BindFailFn defines function that handle payload-binding failure.
View Source
var ( errors.New("unauthorized") )ErrJWTUnauthorized =
View Source
var OpFailFn = func(c *gin.Context, e error) { log.Info("[OpFailFn]", "err", e) c.JSON(http.StatusInternalServerError, gin.H{ "code": 2, "data": e.Error(), }) }
OpFailFn defines function that handle internal error.
View Source
var RetOK = map[string]interface{}{"code": 0, "data": struct{}{}}
RetOK defines JSON response of successful HTTP response.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.