-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e372b71
commit 51af0a9
Showing
12 changed files
with
143 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package modular_test | ||
|
||
import ( | ||
"github.com/kercylan98/minotaur/modular" | ||
"testing" | ||
) | ||
|
||
func TestNewApplication(t *testing.T) { | ||
if modular.NewApplication() == nil { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestRun(t *testing.T) { | ||
application := modular.NewApplication() | ||
modular.RegisterService[*AccountService, AccountServiceExposer](application) | ||
modular.RegisterService[*ConfigService, ConfigServiceExposer](application) | ||
modular.Run(application) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package modular_test | ||
|
||
import ( | ||
"github.com/kercylan98/minotaur/modular" | ||
) | ||
|
||
type AccountService struct { | ||
config ConfigServiceExposer | ||
} | ||
|
||
func (a *AccountService) OnInit(application *modular.Application) { | ||
} | ||
|
||
func (a *AccountService) OnPreload(application *modular.Application) { | ||
a.config = modular.InvokeService[ConfigServiceExposer](application) | ||
} | ||
|
||
func (a *AccountService) OnMount(application *modular.Application) { | ||
} | ||
|
||
func (a *AccountService) OnStart(application *modular.Application) { | ||
// 假设需要使用配置 | ||
a.config.Get("key") | ||
} | ||
|
||
func (a *AccountService) Login() { | ||
|
||
} | ||
|
||
type AccountServiceExposer interface { | ||
Login() | ||
} | ||
|
||
type ConfigService struct { | ||
kv map[string]string | ||
} | ||
|
||
func (c *ConfigService) OnInit(application *modular.Application) { | ||
} | ||
|
||
func (c *ConfigService) OnPreload(application *modular.Application) { | ||
} | ||
|
||
func (c *ConfigService) OnMount(application *modular.Application) { | ||
// 假设从数据库加载 | ||
c.kv = make(map[string]string) | ||
} | ||
|
||
func (c *ConfigService) OnStart(application *modular.Application) { | ||
} | ||
|
||
func (c *ConfigService) Get(key string) string { | ||
if c.kv == nil { | ||
panic("config service not initialized") | ||
} | ||
return key | ||
} | ||
|
||
type ConfigServiceExposer interface { | ||
Get(key string) string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
package collection | ||
|
||
import "github.com/kercylan98/minotaur/utils/generic" | ||
import ( | ||
"github.com/kercylan98/minotaur/toolkit/constraints" | ||
) | ||
|
||
// ComparisonHandler 用于比较 `source` 和 `target` 两个值是否相同的比较函数 | ||
// - 该函数接受两个参数,分别是源值和目标值,返回 true 的情况下即表示两者相同 | ||
type ComparisonHandler[V any] func(source, target V) bool | ||
|
||
// OrderedValueGetter 用于获取 v 的可排序字段值的函数 | ||
type OrderedValueGetter[V any, N generic.Ordered] func(v V) N | ||
type OrderedValueGetter[V any, N constraints.Ordered] func(v V) N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.