From de04d608a9d0471123005fea2de8a90fad1b019b Mon Sep 17 00:00:00 2001 From: Reza Date: Tue, 20 Feb 2024 03:33:13 +0100 Subject: [PATCH] Refactor UserInterface in evo bundle Refactored UserInterface methods and variables in evo bundle for better semantics and accessibility. All the method names --- evo.context.go | 2 +- evo.user.go | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/evo.context.go b/evo.context.go index 9ba83416..d81498c2 100644 --- a/evo.context.go +++ b/evo.context.go @@ -30,7 +30,7 @@ type Request struct { status int _break bool jsonParsedBody *gjson.Result - user *UserInterface + UserInterface *UserInterface } type Response struct { diff --git a/evo.user.go b/evo.user.go index 9635c0e9..60632fd6 100644 --- a/evo.user.go +++ b/evo.user.go @@ -3,11 +3,14 @@ package evo import "github.com/getevo/evo/v2/lib/generic" func (r *Request) User() UserInterface { - if r.user == nil { + if r.UserInterface == nil { var user = (UserInterfaceInstance).FromRequest(r) - r.user = &user + if user == nil { + user = DefaultUserInterface{} + } + r.UserInterface = &user } - return *r.user + return *r.UserInterface } type DefaultUserInterface struct{} @@ -25,15 +28,16 @@ func SetUserInterface(v UserInterface) { } type UserInterface interface { - Name() string - LastName() string - FullName() string - Email() string + GetFirstName() string + GetLastName() string + GetFullName() string + GetEmail() string UUID() string ID() uint64 Anonymous() bool HasPermission(permission string) bool Attributes() Attributes + Interface() interface{} FromRequest(request *Request) UserInterface } @@ -41,19 +45,19 @@ func (d DefaultUserInterface) HasPermission(permission string) bool { return true } -func (d DefaultUserInterface) Name() string { +func (d DefaultUserInterface) GetFirstName() string { return "" } -func (d DefaultUserInterface) LastName() string { +func (d DefaultUserInterface) GetLastName() string { return "" } -func (d DefaultUserInterface) FullName() string { +func (d DefaultUserInterface) GetFullName() string { return "" } -func (d DefaultUserInterface) Email() string { +func (d DefaultUserInterface) GetEmail() string { return "" } @@ -69,6 +73,10 @@ func (d DefaultUserInterface) Anonymous() bool { return true } +func (d DefaultUserInterface) Interface() interface{} { + return d +} + func (d DefaultUserInterface) FromRequest(request *Request) UserInterface { return DefaultUserInterface{} }