Skip to content

Commit a05f3a3

Browse files
ReasnoGGXXLL
andauthored
V0.13.x (#237)
* fix(factory): on reload, close the connection right away. graceful shutdown logic should be implemented in the close function, not in the factory. * fix(cron): test flakes * feat: add eventv2 * wip: prototyping generics api * wip: prototyping generics api * wip: prototyping generics api * feat: ctxmeta support generic * fix: asyncContext.Value interface to any * wip: generics * wip: add once to event * refactor: remove text package * feat: interface{} to any * refactor: remove deprecated cron * test: workflow go-version 1.18beta2 * test: setup-go stable false * test: fix workflow go-version * doc: add listener comment * feat: simplify run group * fix: remove deprecatedcron test * fix: missing StatusChanged * fix: some test * feat: simplify run group * fix: some import style * fix: remove config module dispatcher * fix(otgorm): hooks (#236) * fix(otgorm): hooks * fix: remove debug prints (cherry picked from commit 1afb3d7) * refactor(control): add pool * fix(pool): data race * fix(pool): data race * fix(pool): go vet "call to (*T).Fatalf from a non-test goroutine" * refactor: change leader election semantics. (#238) * refactor: change leader election semantics. Now leader election campaign will not return when the node beomes leader, instead it will block until the leader election session exists, updating status proactively. This change will make leader election status more accurate. * fix(leader): mock driver for test * fix: return if renew fails * test: increase test duration * docs: add jetbrains thanks * fix(cron): example flakes * fix(leader): TestElection block test * fix(leader): missing dispatch when leader status on * fix(leader): test data race * fix(leader): test key conflict * test(ots3): test container of minio * feat: add a simple way to ensure cron jobs to run at least once for each schedule. * doc: add comment * fix(leaderredis): data race Co-authored-by: Trock <[email protected]> * fix: server.go merge conflict * feat(test): upgrade github actions * fix: otredis TestModule_ProvideCommand * fix: workflow lint add setup-go * fix: workflow lint add setup-go * fix: pool.Run need start before call Go method when use async mode. * feat: add pool.Counter to observe the status of pool. Co-authored-by: Trock <[email protected]> Co-authored-by: Trock <[email protected]>
1 parent 5ac3d1c commit a05f3a3

File tree

183 files changed

+2093
-1815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+2093
-1815
lines changed

.github/workflows/go.yml

+35-28
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build:
1010
strategy:
1111
matrix:
12-
go-version: [1.16.x,1.17.x]
12+
go-version: [ 1.18.x ]
1313
runs-on: ubuntu-latest
1414
services:
1515
redis:
@@ -70,44 +70,51 @@ jobs:
7070
options: --name minio-server
7171

7272
steps:
73-
- uses: actions/checkout@v2
73+
- uses: actions/checkout@v3
7474

75-
- name: Set up Go
76-
uses: actions/setup-go@v2
77-
with:
78-
go-version: ${{ matrix.go-version }}
75+
- name: Set up Go
76+
uses: actions/setup-go@v3
77+
with:
78+
stable: false
79+
go-version: ${{ matrix.go-version }}
7980

80-
- uses: actions/cache@v2
81-
id: cache-go-mod
82-
with:
83-
path: ~/go/pkg/mod
84-
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('go.mod') }}
85-
restore-keys: |
86-
${{ runner.os }}-go-${{ matrix.go-version }}
81+
- uses: actions/cache@v3
82+
id: cache-go-mod
83+
with:
84+
path: ~/go/pkg/mod
85+
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('go.mod') }}
86+
restore-keys: |
87+
${{ runner.os }}-go-${{ matrix.go-version }}
8788
88-
- name: Environment Variables from Dotenv
89-
uses: c-py/action-dotenv-to-setenv@v3
89+
- name: Environment Variables from Dotenv
90+
uses: c-py/action-dotenv-to-setenv@v3
9091

91-
- name: Build
92-
if: steps.cache-go-mod.outputs.cache-hit != 'true'
93-
run: go build -v ./...
92+
- name: Build
93+
if: steps.cache-go-mod.outputs.cache-hit != 'true'
94+
run: go build -v ./...
9495

95-
- name: Test
96-
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
96+
- name: Test
97+
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
9798

98-
- name: Upload coverage
99-
uses: codecov/codecov-action@v1
100-
with:
101-
token: ${{ secrets.CODECOV_TOKEN }}
102-
file: coverage.txt
99+
- name: Upload coverage
100+
uses: codecov/codecov-action@v2
101+
with:
102+
token: ${{ secrets.CODECOV_TOKEN }}
103+
file: coverage.txt
103104
lint:
105+
strategy:
106+
matrix:
107+
go-version: [ 1.18.x ]
104108
name: lint
105109
runs-on: ubuntu-latest
106110
steps:
107-
- uses: actions/checkout@v2
111+
- uses: actions/setup-go@v3
112+
with:
113+
go-version: ${{ matrix.go-version }}
114+
- uses: actions/checkout@v3
108115
- name: Lint
109-
uses: golangci/golangci-lint-action@v2
116+
uses: golangci/golangci-lint-action@v3
110117
with:
111-
version: v1.41
118+
version: v1.45.2
112119
args: --disable errcheck --timeout 5m0s
113120
only-new-issues: true

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,4 @@ the new otetcd configuration is not backward compatible.
465465

466466
* **leader:** add leader election package. ([#56](https://github.com/DoNewsCode/core/issues/56)) (@[谷溪]([email protected]))
467467

468+
>>>>>>> origin/master

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,7 @@ Be sure to checkout the documentation section to learn more.
227227
- [Go Kit](https://github.com/DoNewsCode/core-kit) (if multiple transports)
228228
- [Kratos v2](https://github.com/go-kratos/kratos)
229229

230+
## Thanks for JetBrains OS licenses
230231

232+
<a href="https://www.jetbrains.com/?from=Donews/core" target="_blank"><img src="https://user-images.githubusercontent.com/1787798/69898077-4f4e3d00-138f-11ea-81f9-96fb7c49da89.png" width="150" align="middle"/></a>
231233

README_CN.md

+4
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,7 @@ type HTTPProvider interface {
194194
- [Gin](https://github.com/DoNewsCode/core-gin) (如果仅限于 HTTP)
195195
- [Go Kit](https://github.com/DoNewsCode/core-kit) (如果有多个运输工具)
196196
- [kratos](https://github.com/go-kratos/kratos) (当前 v2 已经可以使用)
197+
198+
## 感谢 JetBrains 开源证书支持
199+
200+
<a href="https://www.jetbrains.com/?from=Donews/core" target="_blank"><img src="https://user-images.githubusercontent.com/1787798/69898077-4f4e3d00-138f-11ea-81f9-96fb7c49da89.png" width="150" align="middle"/></a>

c.go

+24-38
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/DoNewsCode/core/contract"
1919
"github.com/DoNewsCode/core/di"
2020
"github.com/DoNewsCode/core/logging"
21+
2122
"github.com/go-kit/log"
2223
"github.com/knadh/koanf/providers/confmap"
2324
"github.com/knadh/koanf/providers/file"
@@ -34,29 +35,25 @@ type C struct {
3435
contract.ConfigAccessor
3536
logging.LevelLogger
3637
*container.Container
37-
contract.Dispatcher
3838
di *dig.Container
3939
baseLogger log.Logger
4040
}
4141

4242
// ConfParser models a parser for configuration. For example, yaml.Parser.
4343
type ConfParser interface {
44-
Unmarshal([]byte) (map[string]interface{}, error)
45-
Marshal(map[string]interface{}) ([]byte, error)
44+
Unmarshal([]byte) (map[string]any, error)
45+
Marshal(map[string]any) ([]byte, error)
4646
}
4747

4848
// ConfProvider models a configuration provider. For example, file.Provider.
4949
type ConfProvider interface {
5050
ReadBytes() ([]byte, error)
51-
Read() (map[string]interface{}, error)
51+
Read() (map[string]any, error)
5252
}
5353

5454
// ConfigProvider provides contract.ConfigAccessor to the core.
5555
type ConfigProvider func(configStack []config.ProviderSet, configWatcher contract.ConfigWatcher) contract.ConfigUnmarshaler
5656

57-
// EventDispatcherProvider provides contract.Dispatcher to the core.
58-
type EventDispatcherProvider func(conf contract.ConfigUnmarshaler) contract.Dispatcher
59-
6057
// DiProvider provides the *dig.Container to the core.
6158
type DiProvider func(conf contract.ConfigUnmarshaler) *dig.Container
6259

@@ -74,12 +71,11 @@ type coreValues struct {
7471
configStack []config.ProviderSet
7572
configWatcher contract.ConfigWatcher
7673
// ConfProvider functions
77-
configProvider ConfigProvider
78-
eventDispatcherProvider EventDispatcherProvider
79-
diProvider DiProvider
80-
appNameProvider AppNameProvider
81-
envProvider EnvProvider
82-
loggerProvider LoggerProvider
74+
configProvider ConfigProvider
75+
diProvider DiProvider
76+
appNameProvider AppNameProvider
77+
envProvider EnvProvider
78+
loggerProvider LoggerProvider
8379
}
8480

8581
// CoreOption is the option to modify core attribute.
@@ -93,8 +89,8 @@ func WithYamlFile(path string) (CoreOption, CoreOption) {
9389
}
9490

9591
// WithInline is a CoreOption that creates a inline config in the configuration stack.
96-
func WithInline(key string, entry interface{}) CoreOption {
97-
return WithConfigStack(confmap.Provider(map[string]interface{}{
92+
func WithInline(key string, entry any) CoreOption {
93+
return WithConfigStack(confmap.Provider(map[string]any{
9894
key: entry,
9995
}, "."), nil)
10096
}
@@ -148,24 +144,16 @@ func SetDiProvider(provider DiProvider) CoreOption {
148144
}
149145
}
150146

151-
// SetEventDispatcherProvider is a CoreOption to replaces the default EventDispatcherProvider.
152-
func SetEventDispatcherProvider(provider EventDispatcherProvider) CoreOption {
153-
return func(values *coreValues) {
154-
values.eventDispatcherProvider = provider
155-
}
156-
}
157-
158147
// New creates a new bare-bones C.
159148
func New(opts ...CoreOption) *C {
160149
values := coreValues{
161-
configStack: []config.ProviderSet{},
162-
configWatcher: nil,
163-
configProvider: ProvideConfig,
164-
appNameProvider: ProvideAppName,
165-
envProvider: ProvideEnv,
166-
loggerProvider: ProvideLogger,
167-
diProvider: ProvideDi,
168-
eventDispatcherProvider: ProvideEventDispatcher,
150+
configStack: []config.ProviderSet{},
151+
configWatcher: nil,
152+
configProvider: ProvideConfig,
153+
appNameProvider: ProvideAppName,
154+
envProvider: ProvideEnv,
155+
loggerProvider: ProvideLogger,
156+
diProvider: ProvideDi,
169157
}
170158
for _, f := range opts {
171159
f(&values)
@@ -175,15 +163,13 @@ func New(opts ...CoreOption) *C {
175163
appName := values.appNameProvider(conf)
176164
logger := values.loggerProvider(conf, appName, env)
177165
diContainer := values.diProvider(conf)
178-
dispatcher := values.eventDispatcherProvider(conf)
179166

180167
c := C{
181168
AppName: appName,
182169
Env: env,
183170
ConfigAccessor: config.WithAccessor(conf),
184171
LevelLogger: logging.WithLevel(logger),
185172
Container: &container.Container{},
186-
Dispatcher: dispatcher,
187173
di: diContainer,
188174
baseLogger: logger,
189175
}
@@ -207,7 +193,7 @@ func Default(opts ...CoreOption) *C {
207193
// container. The semantics of injection follows the same rule of dig.Invoke.
208194
// Note that the module added in this way will not retain any original field
209195
// values, i.e. the module will only contain fields populated by DI container.
210-
func (c *C) AddModule(module interface{}) {
196+
func (c *C) AddModule(module any) {
211197
t := reflect.TypeOf(module)
212198
if t.Kind() == reflect.Ptr && dig.IsIn(t.Elem()) {
213199
err := di.IntoPopulator(c.di).Populate(module)
@@ -252,7 +238,7 @@ func (c *C) Provide(deps di.Deps) {
252238
}
253239
}
254240

255-
func (c *C) provide(constructor interface{}) {
241+
func (c *C) provide(constructor any) {
256242
var (
257243
options []dig.ProvideOption
258244
shouldMakeFunc bool
@@ -342,7 +328,7 @@ func (c *C) ProvideEssentials() {
342328
DIPopulator contract.DIPopulator
343329
Logger log.Logger
344330
LevelLogger logging.LevelLogger
345-
Dispatcher contract.Dispatcher
331+
Lifecycles lifecycleOut
346332
DefaultConfigs []config.ExportedConfig `group:"config,flatten"`
347333
}
348334

@@ -355,8 +341,8 @@ func (c *C) ProvideEssentials() {
355341
ConfigAccessor: c.ConfigAccessor,
356342
Logger: c.baseLogger,
357343
LevelLogger: c.LevelLogger,
358-
Dispatcher: c.Dispatcher,
359344
DIPopulator: di.IntoPopulator(c.di),
345+
Lifecycles: provideLifecycle(),
360346
DefaultConfigs: provideDefaultConfig(),
361347
}
362348
if cc, ok := c.ConfigAccessor.(contract.ConfigRouter); ok {
@@ -391,7 +377,7 @@ func (c *C) Shutdown() {
391377

392378
// AddModuleFunc add the module after Invoking its constructor. Clean up
393379
// functions and errors are handled automatically.
394-
func (c *C) AddModuleFunc(constructor interface{}) {
380+
func (c *C) AddModuleFunc(constructor any) {
395381
c.provide(constructor)
396382
ftype := reflect.TypeOf(constructor)
397383
targetTypes := make([]reflect.Type, 0)
@@ -439,7 +425,7 @@ func (c *C) ApplyRootCommand(command *cobra.Command) {
439425
//
440426
// It internally calls uber's dig library. Consult dig's documentation for
441427
// details. (https://pkg.go.dev/go.uber.org/dig)
442-
func (c *C) Invoke(function interface{}) {
428+
func (c *C) Invoke(function any) {
443429
err := c.di.Invoke(function)
444430
if err != nil {
445431
panic(err)

0 commit comments

Comments
 (0)