Skip to content

Commit 54d21bf

Browse files
authored
feat: allow to register function before call setup (#84)
* feat: allow to register function before call setup * chore: update release notes
1 parent ff7e132 commit 54d21bf

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

app.go

+9
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,15 @@ func (app *App) Setup(setup func(), start func(), stop func()) (allowContinue bo
344344
//loading plugins
345345
//plugins.Discovery(app.environment.GetPluginDir())
346346

347+
callbacks := global.GetFuncBeforeSetup()
348+
if callbacks != nil && len(callbacks) > 0 {
349+
for i, v := range callbacks {
350+
log.Trace("executing func: ", i)
351+
v()
352+
log.Trace("executed func: ", i)
353+
}
354+
}
355+
347356
if setup != nil {
348357
setup()
349358
}

core/global/register.go

+13
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func Env() *env.Env {
135135

136136
var initCallback = []func(){}
137137
var shutdownCallback = []func(){}
138+
var setupInitFunc = []func(){}
138139

139140
func RegisterShutdownCallback(callback func()) {
140141
registerLock.Lock()
@@ -154,6 +155,18 @@ func RegisterInitCallback(callback func()) {
154155
initCallback = append(initCallback, callback)
155156
}
156157

158+
func RegisterFuncBeforeSetup(callback func()) {
159+
registerLock.Lock()
160+
defer registerLock.Unlock()
161+
setupInitFunc = append(setupInitFunc, callback)
162+
}
163+
164+
func GetFuncBeforeSetup() []func() {
165+
registerLock.Lock()
166+
defer registerLock.Unlock()
167+
return setupInitFunc
168+
}
169+
157170
func GetInitCallback() []func() {
158171
registerLock.Lock()
159172
defer registerLock.Unlock()

docs/content.en/docs/release-notes/_index.md

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ title: "Release Notes"
77

88
Information about release notes of INFINI Framework is provided here.
99

10+
11+
## Latest (In development)
12+
13+
### Breaking changes
14+
15+
### Features
16+
- Allow registering functions to execute before application setup (#84)
17+
18+
### Bug fix
19+
20+
### Improvements
21+
22+
1023
## v1.1.2 (2025-02-15)
1124

1225
### Bug fix

0 commit comments

Comments
 (0)