go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/apputil/base_controller.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package apputil
     9  
    10  import (
    11  	"go.charczuk.com/sdk/uuid"
    12  	"go.charczuk.com/sdk/web"
    13  )
    14  
    15  // BaseController holds useful common methods for controllers.
    16  type BaseController struct{}
    17  
    18  // GetUserID gets a userID from a given web context.
    19  //
    20  // You can use this as a proxy for determining if a
    21  // session is authenticated or not.
    22  func (bc BaseController) GetUserID(r web.Context) uuid.UUID {
    23  	return uuid.MustParse(r.Session().UserID)
    24  }