Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
colorway
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
golang
colorway
Commits
f872e60b
Commit
f872e60b
authored
Jul 02, 2025
by
zhengyaoqiu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(database): mongodb
parent
37fa6718
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
105 additions
and
23 deletions
+105
-23
model.go
internal/pkg/database/mongo/base/model.go
+1
-1
option.go
internal/pkg/database/mongo/base/option.go
+1
-1
generate.go
internal/pkg/database/mongo/generate.go
+1
-1
manager.go
internal/pkg/database/mongo/manager.go
+15
-0
productmodelgen.go
internal/pkg/database/mongo/product/productmodelgen.go
+1
-1
producttypes.go
internal/pkg/database/mongo/product/producttypes.go
+76
-4
model.tpl
internal/pkg/database/mongo/templates/mongo/model.tpl
+1
-1
servicecontext.go
internal/rpc/internal/svc/servicecontext.go
+9
-14
No files found.
internal/pkg/database/mongo/model.go
→
internal/pkg/database/mongo/
base/
model.go
View file @
f872e60b
package
model
package
base
import
(
import
(
"context"
"context"
...
...
internal/pkg/database/mongo/option.go
→
internal/pkg/database/mongo/
base/
option.go
View file @
f872e60b
package
model
package
base
import
"go.mongodb.org/mongo-driver/mongo/options"
import
"go.mongodb.org/mongo-driver/mongo/options"
...
...
internal/pkg/database/mongo/generate.go
View file @
f872e60b
package
mo
del
package
mo
ngo
//go:generate goctl template init --home ./templates
//go:generate goctl template init --home ./templates
...
...
internal/pkg/database/mongo/manager.go
0 → 100644
View file @
f872e60b
package
mongo
import
productModel
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/product"
const
DatabasePc3
=
"pc3"
type
Manager
struct
{
ProductModel
productModel
.
ProductModel
}
func
NewManager
(
mongoUrl
string
)
*
Manager
{
return
&
Manager
{
ProductModel
:
productModel
.
NewProductModel
(
mongoUrl
,
DatabasePc3
,
productModel
.
Collection
),
}
}
internal/pkg/database/mongo/product/productmodelgen.go
View file @
f872e60b
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
package
model
package
model
import
(
import
(
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo
/base
"
"github.com/zeromicro/go-zero/core/stores/mon"
"github.com/zeromicro/go-zero/core/stores/mon"
)
)
...
...
internal/pkg/database/mongo/product/producttypes.go
View file @
f872e60b
...
@@ -6,9 +6,81 @@ import (
...
@@ -6,9 +6,81 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/bson/primitive"
)
)
const
Collection
=
"product"
type
Product
struct
{
type
Product
struct
{
ID
primitive
.
ObjectID
`bson:"_id,omitempty" json:"id,omitempty"`
ID
primitive
.
ObjectID
`bson:"_id,omitempty" json:"id,omitempty"`
// TODO: Fill your own fields
StyleNumber
string
`bson:"styleNumber"`
UpdateAt
time
.
Time
`bson:"updateAt,omitempty" json:"updateAt,omitempty"`
Title
ProductTitle
`bson:"title"`
CreateAt
time
.
Time
`bson:"createAt,omitempty" json:"createAt,omitempty"`
Description
string
`bson:"description"`
Season
string
`bson:"season"`
Brand
ProductBrand
`bson:"brand"`
Care
string
`bson:"care"`
MadeIn
string
`bson:"madeIn"`
HsCode
string
`bson:"hsCode"`
InfoSelect
string
`bson:"infoSelect"`
// 商品信息默认选择哪个商品
Colors
[]
ProductColor
`bson:"colors"`
Category
ProductCategory
`bson:"category"`
Compositions
[]
ProductComposition
`bson:"compositions"`
Fits
[]
string
`bson:"fits"`
Genders
[]
ProductGender
`bson:"genders"`
Models
[]
string
`bson:"models"`
UpdateAt
time
.
Time
`bson:"updateAt,omitempty" json:"updateAt,omitempty"`
CreateAt
time
.
Time
`bson:"createAt,omitempty" json:"createAt,omitempty"`
}
type
ProductGender
string
const
(
GenderMan
ProductGender
=
"man"
GenderWoman
ProductGender
=
"woman"
GenderBaby
ProductGender
=
"baby"
GenderGirl
ProductGender
=
"girl"
GenderBoy
ProductGender
=
"boy"
)
type
ProductComposition
struct
{
Part
string
`bson:"part"`
Material
string
`bson:"material"`
Value
string
`bson:"value"`
}
type
ProductCategory
struct
{
Id
string
`bson:"id"`
Name
string
`bson:"name"`
Children
[]
ProductCategory
`json:"children" bson:"children"`
}
type
ProductColor
struct
{
ColorCode
string
`bson:"colorCode"`
Id
string
`bson:"id"`
Name
string
`bson:"name"`
BasicId
string
`bson:"basicId"`
BasicName
string
`bson:"basicName"`
InfoSelect
string
`bson:"infoSelect"`
// 商品信息默认选择哪个商品
Skus
[]
ProductColorSku
`bson:"skus"`
Images
[]
string
`bson:"images"`
}
type
ProductColorSku
struct
{
Pc3SkuId
string
`bson:"pc3SkuId"`
Pc3ProductId
string
`bson:"pc3ProductId"`
ColorSpuStyleNumber
string
`bson:"colorSpuStyleNumber"`
ColorSpuColorCode
string
`bson:"colorSpuColorCode"`
SourceId
string
`bson:"sourceId"`
SiteId
string
`bson:"siteId"`
Size
string
`bson:"size"`
Stock
int
`bson:"stock"`
Price
float64
`bson:"price"`
Currency
string
`bson:"currency"`
}
type
ProductTitle
struct
{
En
string
`bson:"en"`
Cn
string
`bson:"cn"`
}
type
ProductBrand
struct
{
Id
string
`bson:"id"`
Name
string
`bson:"name"`
}
}
internal/pkg/database/mongo/templates/mongo/model.tpl
View file @
f872e60b
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
package model
package model
import (
import (
model "git.chillcy.com/golang/colorway/internal/pkg/database/mongo"
model "git.chillcy.com/golang/colorway/internal/pkg/database/mongo
/base
"
{
{
if
.
Cache
}
}"github.com/zeromicro/go-zero/core/stores/monc"{
{
else
}
}"github.com/zeromicro/go-zero/core/stores/mon"{
{
end
}
}
{
{
if
.
Cache
}
}"github.com/zeromicro/go-zero/core/stores/monc"{
{
else
}
}"github.com/zeromicro/go-zero/core/stores/mon"{
{
end
}
}
)
)
...
...
internal/rpc/internal/svc/servicecontext.go
View file @
f872e60b
...
@@ -4,7 +4,7 @@ import (
...
@@ -4,7 +4,7 @@ import (
"git.chillcy.com/golang/chillcy/pkg/etcd"
"git.chillcy.com/golang/chillcy/pkg/etcd"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/product"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/product"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/source"
"git.chillcy.com/golang/chillcy/project/pc4/pkg/rpc/client/source"
"git.chillcy.com/golang/colorway/internal/pkg/database"
"git.chillcy.com/golang/colorway/internal/pkg/database
/mongo
"
"git.chillcy.com/golang/colorway/internal/rpc/internal/config"
"git.chillcy.com/golang/colorway/internal/rpc/internal/config"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/cache"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/convert"
"git.chillcy.com/golang/colorway/internal/rpc/internal/svc/convert"
...
@@ -12,28 +12,23 @@ import (
...
@@ -12,28 +12,23 @@ import (
)
)
type
ServiceContext
struct
{
type
ServiceContext
struct
{
Config
config
.
Config
Config
config
.
Config
DatabaseManager
*
database
.
Manager
MongoManager
*
mongo
.
Manager
Pc4RpcService
Pc4RpcService
Pc4RpcService
Pc4RpcService
Cache
*
cache
.
Cache
Cache
*
cache
.
Cache
SpuConvert
*
convert
.
Spu
SpuConvert
*
convert
.
Spu
}
}
func
NewServiceContext
(
c
config
.
Config
)
*
ServiceContext
{
func
NewServiceContext
(
c
config
.
Config
)
*
ServiceContext
{
etcd
.
Init
(
etcd
.
Env
(
c
.
Mode
))
etcd
.
Init
(
etcd
.
Env
(
c
.
Mode
))
// todo dsn etcd
dsn
:=
"root:root@tcp(127.0.0.1:3306)/colorway?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=true&loc=Local"
manager
,
err
:=
database
.
NewManager
(
dsn
)
if
err
!=
nil
{
panic
(
err
)
}
pc4RpcProductServiceTarget
:=
etcd
.
Get
(
etcd
.
KeyRpcPc4
)
pc4RpcProductServiceTarget
:=
etcd
.
Get
(
etcd
.
KeyRpcPc4
)
mongoManager
:=
mongo
.
NewManager
(
etcd
.
Get
(
etcd
.
KeyMongoPlatformUri
))
if
etcd
.
GetEnv
()
==
etcd
.
EnvDev
{
if
etcd
.
GetEnv
()
==
etcd
.
EnvDev
{
pc4RpcProductServiceTarget
=
"127.0.0.1:5100"
pc4RpcProductServiceTarget
=
"127.0.0.1:5100"
}
}
svc
:=
&
ServiceContext
{
svc
:=
&
ServiceContext
{
Config
:
c
,
Config
:
c
,
DatabaseManager
:
m
anager
,
MongoManager
:
mongoM
anager
,
Pc4RpcService
:
Pc4RpcService
{
Pc4RpcService
:
Pc4RpcService
{
Product
:
product
.
NewProduct
(
zrpc
.
MustNewClient
(
zrpc
.
RpcClientConf
{
Target
:
pc4RpcProductServiceTarget
})),
Product
:
product
.
NewProduct
(
zrpc
.
MustNewClient
(
zrpc
.
RpcClientConf
{
Target
:
pc4RpcProductServiceTarget
})),
Source
:
source
.
NewSource
(
zrpc
.
MustNewClient
(
zrpc
.
RpcClientConf
{
Target
:
pc4RpcProductServiceTarget
})),
Source
:
source
.
NewSource
(
zrpc
.
MustNewClient
(
zrpc
.
RpcClientConf
{
Target
:
pc4RpcProductServiceTarget
})),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment