-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into refactor/optional-err…
…handler
- Loading branch information
Showing
82 changed files
with
1,287 additions
and
1,100 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,33 @@ | ||
name: build | ||
on: | ||
push: | ||
branches: | ||
- '**' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
name: Lint, Build, and Test | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 2 | ||
strategy: | ||
matrix: | ||
go-version: [1.21, 1.22, 1.23] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Install Dependencies | ||
run: go mod download | ||
- name: Lint | ||
uses: golangci/golangci-lint-action@v6 | ||
with: | ||
version: v1.60 | ||
args: --timeout=5m -v | ||
- name: Build | ||
run: go build -v ./... | ||
- name: Test | ||
run: go test -v ./... |
This file was deleted.
Oops, something went wrong.
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,4 +1,5 @@ | ||
test | ||
|
||
vendor | ||
.idea | ||
.vscode |
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,48 @@ | ||
linters-settings: | ||
lll: | ||
line-length: 140 | ||
funlen: | ||
lines: 70 | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- bodyclose | ||
- errcheck | ||
- dupl | ||
- exhaustive | ||
- funlen | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- gosimple | ||
- govet | ||
- gosec | ||
- ineffassign | ||
- lll | ||
- misspell | ||
- nakedret | ||
- gofumpt | ||
- staticcheck | ||
- stylecheck | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- whitespace | ||
- prealloc | ||
|
||
issues: | ||
exclude-rules: | ||
- path: '(.+)_test\.go' | ||
linters: | ||
- funlen | ||
- goconst | ||
- lll | ||
exclude-dirs: | ||
- example | ||
|
||
service: | ||
golangci-lint-version: 1.60.3 | ||
prepare: | ||
- echo "here I can run custom commands, but no preparation needed for this repo" |
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,119 +1,119 @@ | ||
package chaki | ||
|
||
import ( | ||
"github.com/Trendyol/chaki/internal/di" | ||
"github.com/Trendyol/chaki/module" | ||
"github.com/Trendyol/chaki/util/slc" | ||
) | ||
|
||
type App struct { | ||
injector *di.Injector | ||
options []Option | ||
provides []any | ||
invokes []any | ||
hooks []module.ProvideHook | ||
modules []*module.Module | ||
} | ||
|
||
func New() *App { | ||
app := &App{ | ||
injector: di.NewInjector(), | ||
} | ||
|
||
return app | ||
} | ||
|
||
func (app *App) WithOption(opts ...Option) *App { | ||
app.options = append(app.options, opts...) | ||
return app | ||
} | ||
|
||
func (app *App) Provide(ctr ...any) *App { | ||
ctr = slc.Map(ctr, app.wrapProvideCtr) | ||
app.provides = append(app.provides, ctr...) | ||
return app | ||
} | ||
|
||
func (app *App) wrapProvideCtr(ctr any) any { | ||
for _, a := range app.hooks { | ||
if a.Match(ctr) { | ||
return a.Wrap(ctr) | ||
} | ||
} | ||
|
||
return ctr | ||
} | ||
|
||
func (app *App) Invoke(ctr ...any) *App { | ||
app.invokes = append(app.invokes, ctr...) | ||
return app | ||
} | ||
|
||
func (app *App) Use(modules ...*module.Module) { | ||
for _, m := range modules { | ||
h := m.Meta().ProvideHooks | ||
app.hooks = append(app.hooks, h...) | ||
} | ||
|
||
app.modules = append(app.modules, modules...) | ||
} | ||
|
||
func (app *App) applyStdModules(o *options) error { | ||
cfgm, err := configModule(o.configOptions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
app.Use( | ||
cfgm, | ||
loggerModule(), | ||
) | ||
|
||
return nil | ||
} | ||
|
||
func (app *App) Start(opts ...Option) error { | ||
opts = append(app.options, opts...) | ||
o := getOptions(opts...) | ||
|
||
if err := app.applyStdModules(o); err != nil { | ||
return err | ||
} | ||
|
||
modules := slc.Map(app.modules, func(m *module.Module) string { | ||
return m.Name() | ||
}) | ||
|
||
for _, m := range app.modules { | ||
meta := m.Meta(modules...) | ||
app.injector.Provide(slc.Map(meta.Provides, app.wrapProvideCtr)...) | ||
app.injector.Invoke(meta.Invokes...) | ||
} | ||
|
||
app.injector.Provide(app.provides...) | ||
app.injector.Invoke(app.invokes...) | ||
|
||
return app.injector.Start(o.timeout) | ||
} | ||
|
||
var defaultApp *App = New() | ||
|
||
func Start(p ...Option) error { | ||
return defaultApp.Start(p...) | ||
} | ||
|
||
func Provide(ctr ...any) { | ||
defaultApp.Provide(ctr...) | ||
} | ||
|
||
func Invoke(ctr ...any) { | ||
defaultApp.Invoke(ctr...) | ||
} | ||
|
||
func Replacer[T any](t T) func(T) T { | ||
return func(_ T) T { return t } | ||
} | ||
|
||
func Valuer[T any](t T) func() T { | ||
return func() T { return t } | ||
} | ||
package chaki | ||
|
||
import ( | ||
"github.com/Trendyol/chaki/internal/di" | ||
"github.com/Trendyol/chaki/module" | ||
"github.com/Trendyol/chaki/util/slc" | ||
) | ||
|
||
type App struct { | ||
injector *di.Injector | ||
options []Option | ||
provides []any | ||
invokes []any | ||
hooks []module.ProvideHook | ||
modules []*module.Module | ||
} | ||
|
||
func New() *App { | ||
app := &App{ | ||
injector: di.NewInjector(), | ||
} | ||
|
||
return app | ||
} | ||
|
||
func (app *App) WithOption(opts ...Option) *App { | ||
app.options = append(app.options, opts...) | ||
return app | ||
} | ||
|
||
func (app *App) Provide(ctr ...any) *App { | ||
ctr = slc.Map(ctr, app.wrapProvideCtr) | ||
app.provides = append(app.provides, ctr...) | ||
return app | ||
} | ||
|
||
func (app *App) wrapProvideCtr(ctr any) any { | ||
for _, a := range app.hooks { | ||
if a.Match(ctr) { | ||
return a.Wrap(ctr) | ||
} | ||
} | ||
|
||
return ctr | ||
} | ||
|
||
func (app *App) Invoke(ctr ...any) *App { | ||
app.invokes = append(app.invokes, ctr...) | ||
return app | ||
} | ||
|
||
func (app *App) Use(modules ...*module.Module) { | ||
for _, m := range modules { | ||
h := m.Meta().ProvideHooks | ||
app.hooks = append(app.hooks, h...) | ||
} | ||
|
||
app.modules = append(app.modules, modules...) | ||
} | ||
|
||
func (app *App) applyStdModules(o *options) error { | ||
cfgm, err := configModule(o.configOptions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
app.Use( | ||
cfgm, | ||
loggerModule(), | ||
) | ||
|
||
return nil | ||
} | ||
|
||
func (app *App) Start(opts ...Option) error { | ||
opts = append(app.options, opts...) | ||
o := getOptions(opts...) | ||
|
||
if err := app.applyStdModules(o); err != nil { | ||
return err | ||
} | ||
|
||
modules := slc.Map(app.modules, func(m *module.Module) string { | ||
return m.Name() | ||
}) | ||
|
||
for _, m := range app.modules { | ||
meta := m.Meta(modules...) | ||
app.injector.Provide(slc.Map(meta.Provides, app.wrapProvideCtr)...) | ||
app.injector.Invoke(meta.Invokes...) | ||
} | ||
|
||
app.injector.Provide(app.provides...) | ||
app.injector.Invoke(app.invokes...) | ||
|
||
return app.injector.Start(o.timeout) | ||
} | ||
|
||
var defaultApp *App = New() | ||
|
||
func Start(p ...Option) error { | ||
return defaultApp.Start(p...) | ||
} | ||
|
||
func Provide(ctr ...any) { | ||
defaultApp.Provide(ctr...) | ||
} | ||
|
||
func Invoke(ctr ...any) { | ||
defaultApp.Invoke(ctr...) | ||
} | ||
|
||
func Replacer[T any](t T) func(T) T { | ||
return func(_ T) T { return t } | ||
} | ||
|
||
func Valuer[T any](t T) func() T { | ||
return func() T { return t } | ||
} |
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.