github.com/goravel/framework@v1.13.9/contracts/auth/access/gate.go (about) 1 package access 2 3 import "context" 4 5 //go:generate mockery --name=Gate 6 type Gate interface { 7 // WithContext returns a new Gate instance with the given context. 8 WithContext(ctx context.Context) Gate 9 // Allows determines if the given ability should be granted for the current user. 10 Allows(ability string, arguments map[string]any) bool 11 // Denies determines if the given ability should be denied for the current user. 12 Denies(ability string, arguments map[string]any) bool 13 // Inspect the given ability against the current user. 14 Inspect(ability string, arguments map[string]any) Response 15 // Define a new ability. 16 Define(ability string, callback func(ctx context.Context, arguments map[string]any) Response) 17 // Any one of the given abilities should be granted for the current user. 18 Any(abilities []string, arguments map[string]any) bool 19 // None of the given abilities should be granted for the current user. 20 None(abilities []string, arguments map[string]any) bool 21 // Before register a callback to run before all Gate checks. 22 Before(callback func(ctx context.Context, ability string, arguments map[string]any) Response) 23 // After register a callback to run after all Gate checks. 24 After(callback func(ctx context.Context, ability string, arguments map[string]any, result Response) Response) 25 } 26 27 type Response interface { 28 // Allowed to determine if the response was allowed. 29 Allowed() bool 30 // Message to get the response message. 31 Message() string 32 }