Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add interface comments #292

Merged
merged 6 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions contracts/auth/access/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ import "context"

//go:generate mockery --name=Gate
type Gate interface {
// WithContext returns a new Gate instance with the given context.
WithContext(ctx context.Context) Gate
// Allows determines if the given ability should be granted for the current user.
Allows(ability string, arguments map[string]any) bool
// Denies determines if the given ability should be denied for the current user.
Denies(ability string, arguments map[string]any) bool
// Inspect the given ability against the current user.
Inspect(ability string, arguments map[string]any) Response
// Define a new ability.
Define(ability string, callback func(ctx context.Context, arguments map[string]any) Response)
// Any one of the given abilities should be granted for the current user.
Any(abilities []string, arguments map[string]any) bool
// None of the given abilities should be granted for the current user.
None(abilities []string, arguments map[string]any) bool
// Before register a callback to run before all Gate checks.
Before(callback func(ctx context.Context, ability string, arguments map[string]any) Response)
// After register a callback to run after all Gate checks.
After(callback func(ctx context.Context, ability string, arguments map[string]any, result Response) Response)
}

type Response interface {
// Allowed to determine if the response was allowed.
Allowed() bool
// Message to get the response message.
Message() string
}
7 changes: 7 additions & 0 deletions contracts/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import (

//go:generate mockery --name=Auth
type Auth interface {
// Guard attempts to get the guard against the local cache.
Guard(name string) Auth
// Parse the given token.
Parse(ctx http.Context, token string) (*Payload, error)
// User returns the current authenticated user.
User(ctx http.Context, user any) error
// Login logs a user into the application.
Login(ctx http.Context, user any) (token string, err error)
// LoginUsingID logs the given user ID into the application.
LoginUsingID(ctx http.Context, id any) (token string, err error)
// Refresh the token for the current user.
Refresh(ctx http.Context) (token string, err error)
// Logout logs the user out of the application.
Logout(ctx http.Context) error
}

Expand Down
28 changes: 20 additions & 8 deletions contracts/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,50 @@ type Cache interface {
type Driver interface {
//Add Driver an item in the cache if the key does not exist.
Add(key string, value any, t time.Duration) bool
//Decrement decrements the value of an item in the cache.
Decrement(key string, value ...int) (int, error)
//Forever Driver an item in the cache indefinitely.
Forever(key string, value any) bool
//Forget Remove an item from the cache.
//Forget removes an item from the cache.
Forget(key string) bool
//Flush Remove all items from the cache.
//Flush remove all items from the cache.
Flush() bool
//Get Retrieve an item from the cache by key.
//Get retrieve an item from the cache by key.
Get(key string, def ...any) any
// GetBool retrieves an item from the cache by key as a boolean.
GetBool(key string, def ...bool) bool
// GetInt retrieves an item from the cache by key as an integer.
GetInt(key string, def ...int) int
// GetInt64 retrieves an item from the cache by key as a 64-bit integer.
GetInt64(key string, def ...int64) int64
// GetString retrieves an item from the cache by key as a string.
GetString(key string, def ...string) string
//Has Check an item exists in the cache.
//Has check an item exists in the cache.
Has(key string) bool
//Increment increments the value of an item in the cache.
Increment(key string, value ...int) (int, error)
//Lock get a lock instance.
Lock(key string, t ...time.Duration) Lock
//Put Driver an item in the cache for a given time.
// Put Driver an item in the cache for a given time.
Put(key string, value any, t time.Duration) error
//Pull Retrieve an item from the cache and delete it.
//Pull retrieve an item from the cache and delete it.
Pull(key string, def ...any) any
//Remember Get an item from the cache, or execute the given Closure and store the result.
// Remember gets an item from the cache, or execute the given Closure and store the result.
Remember(key string, ttl time.Duration, callback func() (any, error)) (any, error)
//RememberForever Get an item from the cache, or execute the given Closure and store the result forever.
//RememberForever get an item from the cache, or execute the given Closure and store the result forever.
RememberForever(key string, callback func() (any, error)) (any, error)
//WithContext returns a new Cache instance with the given context.
kkumar-gcc marked this conversation as resolved.
Show resolved Hide resolved
WithContext(ctx context.Context) Driver
}

//go:generate mockery --name=Lock
type Lock interface {
// Block attempt to acquire the lock for the given number of seconds.
Block(t time.Duration, callback ...func()) bool
// Get attempts to acquire the lock.
Get(callback ...func()) bool
// Release the lock.
Release() bool
// ForceRelease releases the lock in disregard of ownership.
ForceRelease() bool
}
12 changes: 6 additions & 6 deletions contracts/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package config

//go:generate mockery --name=Config
type Config interface {
//Env Get config from env.
// Env get config from env.
Env(envName string, defaultValue ...any) any
//Add config to application.
// Add config to application.
Add(name string, configuration any)
//Get config from application.
// Get config from application.
Get(path string, defaultValue ...any) any
//GetString Get string type config from application.
// GetString get string type config from application.
GetString(path string, defaultValue ...any) string
//GetInt Get int type config from application.
// GetInt get int type config from application.
GetInt(path string, defaultValue ...any) int
//GetBool Get bool type config from application.
// GetBool get bool type config from application.
GetBool(path string, defaultValue ...any) bool
}
8 changes: 4 additions & 4 deletions contracts/console/artisan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package console

//go:generate mockery --name=Artisan
type Artisan interface {
//Register commands.
// Register commands.
Register(commands []Command)

//Call Run an Artisan console command by name.
// Call run an Artisan console command by name.
Call(command string)

//CallAndExit Run an Artisan console command by name and exit.
// CallAndExit run an Artisan console command by name and exit.
CallAndExit(command string)

//Run a command. args include: ["./main", "artisan", "command"]
// Run a command. args include: ["./main", "artisan", "command"]
Run(args []string, exitIfArtisan bool)
}
19 changes: 15 additions & 4 deletions contracts/console/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,38 @@ import (
)

type Command interface {
//Signature The name and signature of the console command.
// Signature set the unique signature for the command.
Signature() string
//Description The console command description.
// Description the console command description.
Description() string
//Extend The console command extend.
// Extend the console command extend.
Extend() command.Extend
//Handle Execute the console command.
// Handle execute the console command.
Handle(ctx Context) error
}

//go:generate mockery --name=Context
type Context interface {
// Argument get the value of a command argument.
Argument(index int) string
// Arguments get all the arguments passed to command.
Arguments() []string
// Option gets the value of a command option.
Option(key string) string
// OptionSlice looks up the value of a local StringSliceFlag, returns nil if not found
OptionSlice(key string) []string
// OptionBool looks up the value of a local BoolFlag, returns false if not found
OptionBool(key string) bool
// OptionFloat64 looks up the value of a local Float64Flag, returns zero if not found
OptionFloat64(key string) float64
// OptionFloat64Slice looks up the value of a local Float64SliceFlag, returns nil if not found
OptionFloat64Slice(key string) []float64
// OptionInt looks up the value of a local IntFlag, returns zero if not found
OptionInt(key string) int
// OptionIntSlice looks up the value of a local IntSliceFlag, returns nil if not found
OptionIntSlice(key string) []int
// OptionInt64 looks up the value of a local Int64Flag, returns zero if not found
OptionInt64(key string) int64
// OptionInt64Slice looks up the value of a local Int64SliceFlag, returns nil if not found
OptionInt64Slice(key string) []int64
}
1 change: 1 addition & 0 deletions contracts/console/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Extend struct {
}

type Flag interface {
// Type gets a flag type.
Type() string
}

Expand Down
2 changes: 2 additions & 0 deletions contracts/database/factory/factory.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package factory

type Factory interface {
// Definition defines the model's default state.
Definition() map[string]any
}

type Model interface {
// Factory creates a new factory instance for the model.
Factory() Factory
}
8 changes: 8 additions & 0 deletions contracts/database/orm/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ const EventForceDeleting EventType = "force_deleting"
const EventForceDeleted EventType = "force_deleted"

type Event interface {
// Context returns the event context.
Context() context.Context
// GetAttribute returns the attribute value for the given key.
GetAttribute(key string) any
// GetOriginal returns the original attribute value for the given key.
GetOriginal(key string, def ...any) any
// IsDirty returns true if the given column is dirty.
IsDirty(columns ...string) bool
// IsClean returns true if the given column is clean.
IsClean(columns ...string) bool
// Query returns the query instance.
Query() Query
// SetAttribute sets the attribute value for the given key.
SetAttribute(key string, value any)
}

type DispatchesEvents interface {
// DispatchesEvents returns the event handlers.
DispatchesEvents() map[EventType]func(Event) error
}
4 changes: 4 additions & 0 deletions contracts/database/orm/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package orm

//go:generate mockery --name=Factory
type Factory interface {
// Count sets the number of models that should be generated.
Count(count int) Factory
// Create creates a model and persists it to the database.
Create(value any, attributes ...map[string]any) error
// CreateQuietly creates a model and persists it to the database without firing any model events.
CreateQuietly(value any, attributes ...map[string]any) error
// Make creates a model and returns it, but does not persist it to the database.
Make(value any, attributes ...map[string]any) error
}
11 changes: 11 additions & 0 deletions contracts/database/orm/observer.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package orm

type Observer interface {
// Retrieved called when the model is retrieved from the database.
Retrieved(Event) error
// Creating called when the model is being created.
Creating(Event) error
// Created called when the model has been created.
Created(Event) error
// Updating called when the model is being updated.
Updating(Event) error
// Updated called when the model has been updated.
Updated(Event) error
// Saving called when the model is being saved.
Saving(Event) error
// Saved called when the model has been saved.
Saved(Event) error
// Deleting called when the model is being deleted.
Deleting(Event) error
// Deleted called when the model has been deleted.
Deleted(Event) error
// ForceDeleting called when the model is being force deleted.
ForceDeleting(Event) error
// ForceDeleted called when the model has been force deleted.
ForceDeleted(Event) error
}
Loading