Skip to content

Commit

Permalink
feat: include meta tag in api (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Oct 14, 2024
1 parent 97fa071 commit 7059cf9
Show file tree
Hide file tree
Showing 38 changed files with 790 additions and 370 deletions.
2 changes: 1 addition & 1 deletion canal/canal.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Main() error {

// driver and connector
fx.Provide(
driver.NewMysqlConnectionPool,
driver.NewMysqlSqlDB,
driver.NewRedisClient, logger.Copy, cache.NewRedisCache,
subject.NewMysqlRepo, search.New, session.NewMysqlRepo, session.New,
driver.NewS3,
Expand Down
183 changes: 0 additions & 183 deletions canal/stream/redis_stream.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/archive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func start(out string) {
err := fx.New(
fx.NopLogger,
fx.Provide(
driver.NewMysqlConnectionPool, dal.NewDB,
driver.NewMysqlSqlDB, dal.NewGormDB,

config.NewAppConfig, logger.Copy,

Expand Down Expand Up @@ -210,7 +210,7 @@ type Subject struct {

type Tag struct {
Name string `json:"name"`
Count int `json:"count"`
Count uint `json:"count"`
}

func exportSubjects(q *query.Query, w io.Writer) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/gen/gorm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ func main() {
panic("failed to read config: " + err.Error())
}

conn, err := driver.NewMysqlConnectionPool(c)
conn, err := driver.NewMysqlSqlDB(c)
if err != nil {
panic(err)
}

db, err := dal.NewDB(conn, c)
db, err := dal.NewGormDB(conn, c)
if err != nil {
panic(err)
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/web/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/bangumi/server/internal/revision"
"github.com/bangumi/server/internal/search"
"github.com/bangumi/server/internal/subject"
"github.com/bangumi/server/internal/tag"
"github.com/bangumi/server/internal/timeline"
"github.com/bangumi/server/internal/user"
"github.com/bangumi/server/web"
Expand All @@ -65,7 +66,8 @@ func start() error {
fx.Provide(
config.AppConfigReader(config.AppTypeHTTP),
driver.NewRedisClientWithMetrics, // redis
driver.NewMysqlConnectionPool, // mysql
driver.NewMysqlSqlDB, // mysql
driver.NewRueidisClient,
func() *resty.Client {
httpClient := resty.New().SetJSONEscapeHTML(false)
httpClient.JSONUnmarshal = json.Unmarshal
Expand All @@ -74,6 +76,8 @@ func start() error {
},
),

fx.Invoke(dal.SetupMetrics),

dal.Module,

fx.Provide(
Expand All @@ -87,6 +91,8 @@ func start() error {

dam.New, subject.NewMysqlRepo, subject.NewCachedRepo, person.NewMysqlRepo,

tag.NewCachedRepo, tag.NewMysqlRepo,

auth.NewService, person.NewService, search.New,
),

Expand Down
2 changes: 1 addition & 1 deletion dal/fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

var Module = fx.Module("dal",
fx.Provide(
NewDB,
NewGormDB,
query.Use,
NewMysqlTransaction,
func(db *sql.DB) *sqlx.DB {
Expand Down
2 changes: 1 addition & 1 deletion dal/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"gorm.io/gorm"
)

func setupMetrics(db *gorm.DB, conn *sql.DB) error {
func SetupMetrics(db *gorm.DB, conn *sql.DB) error {
var DatabaseQuery = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "chii_db_execute_total",
Expand Down
6 changes: 1 addition & 5 deletions dal/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/bangumi/server/internal/pkg/logger"
)

func NewDB(conn *sql.DB, c config.AppConfig) (*gorm.DB, error) {
func NewGormDB(conn *sql.DB, c config.AppConfig) (*gorm.DB, error) {
var gLog gormLogger.Interface
if c.Debug.Gorm {
logger.Info("enable gorm debug mode, will log all sql")
Expand All @@ -51,9 +51,5 @@ func NewDB(conn *sql.DB, c config.AppConfig) (*gorm.DB, error) {
return nil, errgo.Wrap(err, "create dal")
}

if err = setupMetrics(db, conn); err != nil {
return nil, errgo.Wrap(err, "setup metrics")
}

return db, nil
}
4 changes: 2 additions & 2 deletions dal/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func TestNewDB(t *testing.T) {
cfg, err := config.NewAppConfig()
require.NoError(t, err)

conn, err := driver.NewMysqlConnectionPool(cfg)
conn, err := driver.NewMysqlSqlDB(cfg)
require.NoError(t, err)
db, err := dal.NewDB(conn, cfg)
db, err := dal.NewGormDB(conn, cfg)
require.NoError(t, err)

err = db.Exec("select 0;").Error
Expand Down
14 changes: 14 additions & 0 deletions etc/mock.task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ vars:
tasks:
all:
cmds:
- task: Tag
- task: session-manager
- task: session-repo
- task: cache
Expand Down Expand Up @@ -98,6 +99,19 @@ tasks:
MOCK_STRUCT: "AuthService"
INTERFACE: Service

"Tag":
sources:
- internal/tag/domain.go
- ./internal/pkg/tools/go.mod
generates:
- internal/mocks/TagRepo.go
cmds:
- task: base-mock
vars:
SRC_DIR: ./internal/tag
INTERFACE: "Repo"
MOCK_STRUCT: "TagRepo"

"CharacterRepo":
sources:
- ./internal/character/domain/.go
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/validator/v10 v10.22.1
github.com/go-redis/redismock/v9 v9.2.0
github.com/go-resty/resty/v2 v2.15.3
github.com/go-sql-driver/mysql v1.8.1
github.com/ilyakaznacheev/cleanenv v1.5.0
Expand All @@ -25,6 +24,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/client_golang v1.20.4
github.com/redis/go-redis/v9 v9.6.1
github.com/redis/rueidis v1.0.47
github.com/samber/lo v1.47.0
github.com/segmentio/kafka-go v0.4.47
github.com/spf13/cobra v1.8.1
Expand Down Expand Up @@ -68,7 +68,6 @@ require (
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
Expand Down
Loading

0 comments on commit 7059cf9

Please sign in to comment.