Mostly just function signatures at the moment Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
51 lines
1.0 KiB
Go
51 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
auth_storage "git.ewellenr.ca/receipt_indexer/backend/internal/storage/auth"
|
|
)
|
|
|
|
type userKey string
|
|
|
|
const userCtx userKey = "user"
|
|
|
|
func (app *application) getUserHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
}
|
|
|
|
func (app *application) getUsersHandler(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
func (app *application) deleteUserHandler(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
|
|
func (app *application) getUser(ctx context.Context, userID int64) (*auth_storage.User, error) {
|
|
if !app.config.redisCfg.enabled {
|
|
return app.auth.Users.GetByID(ctx, userID)
|
|
}
|
|
|
|
user, err := app.cacheStorage.Users.Get(ctx, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if user == nil {
|
|
user, err = app.auth.Users.GetByID(ctx, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := app.cacheStorage.Users.Set(ctx, user); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return user, nil
|
|
}
|
|
|
|
func getUserFromContext(r *http.Request) *auth_storage.User {
|
|
user, _ := r.Context().Value(userCtx).(*auth_storage.User)
|
|
return user
|
|
}
|