GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: subject search (#210) · gitLibs/server@ebdc138

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Taskfile.yaml
  • config.example.yaml
  • etc
    • mock.task.yaml
  • go.mod
  • go.sum
  • internal
    • canal
      • canal.go
      • event.go
      • mq.go
      • mq_internal_test.go
      • on_subject.go
      • on_user.go
    • config
      • new.go
    • mocks
      • SearchClient.go
    • pkg
      • obj
        • get.go
      • test
        • web.go
    • search
      • client.go
      • extract_internal_test.go
      • extractor.common.go
      • handle.go
      • index.go
      • noop.go
      • readme.md
    • web
      • fx.go
      • handler.go
      • handler
        • new.go
        • search.go
  • main.go
  • openapi
    • v0.yaml
  • pkg/wiki
    • parser.go
  • readme.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Taskfile.yaml‎

Copy file name to clipboardExpand all lines: Taskfile.yaml
+12-5Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ tasks:
5454
- golangci-lint run --fix
5555

5656
test:
57-
desc: Run tests without mysql and redis.
57+
desc: Run mocked tests, need nothing.
5858
cmds:
5959
- go test -timeout 3s -tags test {{.CLI_ARGS}} ./...
6060
env:
@@ -65,18 +65,25 @@ tasks:
6565
cmds:
6666
- go test -bench=. -benchmem ./pkg/wiki
6767

68-
test-all:
69-
desc: Run all tests, need mysql and redis, except hCaptcha tests, alias for `TEST_MYSQL=1 TEST_REDIS=1 task test`
68+
test-db:
69+
desc: Run mocked tests, and tests require mysql and redis. alias for `TEST_MYSQL=1 TEST_REDIS=1 task test`
7070
cmds:
7171
- go test -timeout 3s -tags test {{.CLI_ARGS}} ./...
7272
env:
7373
TEST_MYSQL: "1"
7474
TEST_REDIS: "1"
7575

76-
test-all-with-http:
77-
desc: Run all tests, need mysql and redis, alias for `TEST_MYSQL=1 TEST_REDIS=1 TEST_HTTP=1 task test`
76+
test-http:
77+
desc: Run mocked tests, and tests require external HTTP resources, alias for `TEST_HTTP=1 task test`
7878
cmds:
7979
- go test -timeout 3s -tags test {{.CLI_ARGS}} ./...
80+
env:
81+
TEST_HTTP: "1"
82+
83+
test-all:
84+
desc: Run all tests.
85+
cmds:
86+
- go test -timeout 10s -tags test ./...
8087
env:
8188
TEST_MYSQL: "1"
8289
TEST_REDIS: "1"
Collapse file

‎config.example.yaml‎

Copy file name to clipboardExpand all lines: config.example.yaml
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ mysql_db: bangumi
1313

1414
hcaptcha_secret_key: 0x0000000000000000000000000000000000000000
1515

16+
# 如果为空字符串则不会启用搜索相关的功能。
17+
meilisearch_url: ""
18+
meilisearch_key: ""
19+
1620
debug:
1721
gorm: true
1822
nsfw_word: "里番|无码|18x|エロ"
Collapse file

‎etc/mock.task.yaml‎

Copy file name to clipboardExpand all lines: etc/mock.task.yaml
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ tasks:
3535
- GroupRepo
3636
- CollectionRepo
3737
- TopicRepo
38+
- SearchClient
3839

3940
base-mock:
4041
deps:
@@ -271,3 +272,16 @@ tasks:
271272
vars:
272273
SRC_DIR: ./internal/domain
273274
INTERFACE: TopicRepo
275+
276+
SearchClient:
277+
sources:
278+
- internal/search/client.go
279+
- ./internal/pkg/tools/go.mod
280+
generates:
281+
- internal/mocks/SearchClient.go
282+
cmds:
283+
- task: base-mock
284+
vars:
285+
SRC_DIR: ./internal/search
286+
INTERFACE: Client
287+
MOCK_STRUCT: SearchClient
Collapse file

‎go.mod‎

Copy file name to clipboardExpand all lines: go.mod
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/ilyakaznacheev/cleanenv v1.3.0
2020
github.com/jarcoal/httpmock v1.2.0
2121
github.com/mattn/go-colorable v0.1.13
22+
github.com/meilisearch/meilisearch-go v0.20.1
2223
github.com/mitchellh/mapstructure v1.5.0
2324
github.com/prometheus/client_golang v1.13.0
2425
github.com/segmentio/kafka-go v0.4.34
@@ -30,7 +31,6 @@ require (
3031
go.uber.org/fx v1.18.1
3132
go.uber.org/zap v1.23.0
3233
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503
33-
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde
3434
gopkg.in/yaml.v3 v3.0.1
3535
gorm.io/driver/mysql v1.3.6
3636
gorm.io/gen v0.3.15
@@ -48,15 +48,18 @@ require (
4848
github.com/davecgh/go-spew v1.1.1 // indirect
4949
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
5050
github.com/fsnotify/fsnotify v1.5.4 // indirect
51+
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
5152
github.com/golang/protobuf v1.5.2 // indirect
5253
github.com/google/uuid v1.3.0 // indirect
5354
github.com/huandu/xstrings v1.3.2 // indirect
5455
github.com/imdario/mergo v0.3.13 // indirect
5556
github.com/jinzhu/inflection v1.0.0 // indirect
5657
github.com/jinzhu/now v1.1.5 // indirect
5758
github.com/joho/godotenv v1.4.0 // indirect
58-
github.com/klauspost/compress v1.15.8 // indirect
59+
github.com/josharian/intern v1.0.0 // indirect
60+
github.com/klauspost/compress v1.15.9 // indirect
5961
github.com/leodido/go-urn v1.2.1 // indirect
62+
github.com/mailru/easyjson v0.7.7 // indirect
6063
github.com/mattn/go-isatty v0.0.16 // indirect
6164
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
6265
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
@@ -78,7 +81,7 @@ require (
7881
go.uber.org/dig v1.15.0 // indirect
7982
go.uber.org/multierr v1.8.0 // indirect
8083
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
81-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
84+
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced // indirect
8285
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
8386
golang.org/x/text v0.3.7 // indirect
8487
golang.org/x/tools v0.1.12 // indirect
Collapse file

‎go.sum‎

Copy file name to clipboardExpand all lines: go.sum
+14-5Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFG
172172
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
173173
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
174174
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
175+
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
176+
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
175177
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
176178
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
177179
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
@@ -342,6 +344,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht
342344
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
343345
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
344346
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
347+
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
348+
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
345349
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
346350
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
347351
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
@@ -357,9 +361,10 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
357361
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
358362
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
359363
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
364+
github.com/klauspost/compress v1.15.6/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
360365
github.com/klauspost/compress v1.15.7/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
361-
github.com/klauspost/compress v1.15.8 h1:JahtItbkWjf2jzm/T+qgMxkP9EMHsqEUA6vCMGmXvhA=
362-
github.com/klauspost/compress v1.15.8/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
366+
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
367+
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
363368
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
364369
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
365370
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -382,6 +387,8 @@ github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
382387
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
383388
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
384389
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
390+
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
391+
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
385392
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
386393
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
387394
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
@@ -403,6 +410,8 @@ github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW
403410
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
404411
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
405412
github.com/maxatome/go-testdeep v1.11.0 h1:Tgh5efyCYyJFGUYiT0qxBSIDeXw0F5zSoatlou685kk=
413+
github.com/meilisearch/meilisearch-go v0.20.1 h1:Lddkf3C/f/Uv0+eD2f9qtpykmK5E7IZStJpIV0UVxu4=
414+
github.com/meilisearch/meilisearch-go v0.20.1/go.mod h1:jUGQlQNFYcni/mSG/d71utwqPuKG0bRT+63Xenw2B+0=
406415
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
407416
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
408417
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
@@ -580,6 +589,7 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb
580589
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
581590
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
582591
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
592+
github.com/valyala/fasthttp v1.37.1-0.20220607072126-8a320890c08d/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
583593
github.com/valyala/fasthttp v1.38.0 h1:yTjSSNjuDi2PPvXY2836bIwLmiTS2T4T9p1coQshpco=
584594
github.com/valyala/fasthttp v1.38.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
585595
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
@@ -732,8 +742,9 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
732742
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
733743
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
734744
golang.org/x/net v0.0.0-20220706163947-c90051bbdb60/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
735-
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
736745
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
746+
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced h1:3dYNDff0VT5xj+mbj2XucFst9WKk6PdGOrb9n+SbIvw=
747+
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
737748
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
738749
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
739750
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -752,8 +763,6 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
752763
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
753764
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
754765
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
755-
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde h1:ejfdSekXMDxDLbRrJMwUk6KnSLZ2McaUCVcIKM+N6jc=
756-
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
757766
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
758767
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
759768
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Collapse file

‎internal/canal/canal.go‎

Copy file name to clipboard
+105Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published
5+
// by the Free Software Foundation, version 3.
6+
//
7+
// This program is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
// See the GNU Affero General Public License for more details.
11+
//
12+
// You should have received a copy of the GNU Affero General Public License
13+
// along with this program. If not, see <https://www.gnu.org/licenses/>
14+
15+
//nolint:depguard
16+
package canal
17+
18+
import (
19+
"context"
20+
"os"
21+
"os/signal"
22+
"syscall"
23+
24+
"github.com/segmentio/kafka-go"
25+
"go.uber.org/fx"
26+
27+
"github.com/bangumi/server/internal/cache"
28+
"github.com/bangumi/server/internal/config"
29+
"github.com/bangumi/server/internal/dal"
30+
"github.com/bangumi/server/internal/driver"
31+
"github.com/bangumi/server/internal/metrics"
32+
"github.com/bangumi/server/internal/pkg/errgo"
33+
"github.com/bangumi/server/internal/pkg/logger"
34+
"github.com/bangumi/server/internal/search"
35+
"github.com/bangumi/server/internal/subject"
36+
"github.com/bangumi/server/internal/web/session"
37+
)
38+
39+
func Main() error {
40+
e, err := getEventHandler()
41+
if err != nil {
42+
return err
43+
}
44+
45+
shutdown := make(chan int)
46+
sigChan := make(chan os.Signal, 1)
47+
// register for interrupt (Ctrl+C) and SIGTERM (docker)
48+
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
49+
go func() {
50+
<-sigChan
51+
logger.Info("receive signal, shutdown")
52+
e.Close()
53+
shutdown <- 1
54+
}()
55+
56+
select {
57+
case err := <-e.start(context.Background()):
58+
return err
59+
case <-shutdown:
60+
return nil
61+
}
62+
}
63+
64+
func getEventHandler() (*eventHandler, error) {
65+
var h *eventHandler
66+
67+
err := fx.New(
68+
logger.FxLogger(),
69+
config.Module,
70+
71+
dal.Module,
72+
73+
// driver and connector
74+
fx.Provide(
75+
driver.NewMysqlConnectionPool, metrics.NewScope,
76+
driver.NewRedisClient, logger.Copy, cache.NewRedisCache,
77+
subject.NewMysqlRepo,
78+
search.New,
79+
session.NewMysqlRepo, session.New,
80+
81+
func(c config.AppConfig) *kafka.Reader {
82+
topics := []string{
83+
"chii.bangumi.chii_subject_fields",
84+
"chii.bangumi.chii_subjects",
85+
"chii.bangumi.chii_members",
86+
}
87+
return kafka.NewReader(kafka.ReaderConfig{
88+
Brokers: []string{c.KafkaBroker},
89+
GroupID: groupID,
90+
GroupTopics: topics,
91+
})
92+
},
93+
94+
newEventHandler,
95+
),
96+
97+
fx.Populate(&h),
98+
).Err()
99+
100+
if err != nil {
101+
return nil, errgo.Wrap(err, "fx")
102+
}
103+
104+
return h, nil
105+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.