Back to

Package util

Latest Go to latest

The latest major version is .

Published: Jan 10, 2019 | License: Apache-2.0 | Module:



const (
	// JWTSecret defines default JWT secret
	JWTSecret = "istioIsAwesome"


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.

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.

var (
	// ErrJWTUnauthorized is returned when the token isn't authorized.
	ErrJWTUnauthorized = errors.New("unauthorized")
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.

var RetOK = map[string]interface{}{"code": 0, "data": struct{}{}}

RetOK defines JSON response of successful HTTP response.

func Home

func Home() string

Home returns home path.

func Kubeconfig

func Kubeconfig() string

Kubeconfig returns kube config path.

func User

func User(c *gin.Context) model.User

User returns current login user.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier