feat: Add feature system to Core (#17)
This commit introduces a new feature system to the Core struct. A new `Features` struct is defined in `pkg/core/interfaces.go` with an `IsEnabled` method to check if a feature is enabled. The `Core` struct is updated to include this new `Features` struct, which is initialized in the `New` function. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
parent
41ed9baa12
commit
0c3321bfab
2 changed files with 17 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ import (
|
||||||
func New(opts ...Option) (*Core, error) {
|
func New(opts ...Option) (*Core, error) {
|
||||||
c := &Core{
|
c := &Core{
|
||||||
services: make(map[string]any),
|
services: make(map[string]any),
|
||||||
|
Features: &Features{},
|
||||||
}
|
}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(c); err != nil {
|
if err := o(c); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,21 @@ type Contract struct {
|
||||||
DontPanic bool
|
DontPanic bool
|
||||||
DisableLogging bool
|
DisableLogging bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Features provides a way to check if a feature is enabled.
|
||||||
|
type Features struct {
|
||||||
|
Flags []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEnabled returns true if the given feature is enabled.
|
||||||
|
func (f *Features) IsEnabled(feature string) bool {
|
||||||
|
for _, flag := range f.Flags {
|
||||||
|
if flag == feature {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
type Option func(*Core) error
|
type Option func(*Core) error
|
||||||
type Message interface{}
|
type Message interface{}
|
||||||
type Core struct {
|
type Core struct {
|
||||||
|
|
@ -23,6 +38,7 @@ type Core struct {
|
||||||
initErr error
|
initErr error
|
||||||
App *application.App
|
App *application.App
|
||||||
assets embed.FS
|
assets embed.FS
|
||||||
|
Features *Features
|
||||||
serviceLock bool
|
serviceLock bool
|
||||||
ipcMu sync.RWMutex
|
ipcMu sync.RWMutex
|
||||||
ipcHandlers []func(*Core, Message) error
|
ipcHandlers []func(*Core, Message) error
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue