You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: user.go
    path of file: ./repos/ShadowEditor/server/server
    
    the code of the file until where you have to start completion: // Copyright 2017-2020 The ShadowEditor Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
//
// For mo
    
func GetCurrentUser(r *http.Request) (*system.User, error) {
	var cookie *http.Cookie = nil
	for _, item := range r.Cookies() {
		if item.Name == "token" {
			cookie = item
			break
		}
	}

	// get current user
	var user *system.User = nil
	if cookie != nil {
		token, err := jwt.Parse(cookie.Value, func(token *jwt.Token) (interface{}, error) {
			if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
				return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
			}
			return []byte(Config.Authority.SecretKey), nil
		})
		if claims, ok := token.Claims.(jwt.MapClaims); ok && token != nil && token.Valid {
			user, _ = GetUser(claims["userID"].(string))
		} else {
			Logger.Error(err.Error())
		}
	}

	// user has LOGIN auth when login
	if user != nil && user.OperatingAuthorities != nil {
		user.OperatingAuthorities = append(user.OperatingAuthorities, string(Login))
	}

	return user, nil
}