feat: import services and standardize Go 1.26.5

This commit is contained in:
2026-08-09 10:43:45 +08:00
parent 689c74b28f
commit 86024fa81d
1456 changed files with 220765 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
# content

View File

@@ -0,0 +1,49 @@
version: v2
plugins:
- local: protoc-gen-go
out: pb
opt:
- paths=source_relative
- local: protoc-gen-go
out: ../../bsm-sdk/client/golang/feed
opt:
- paths=source_relative
- local: protoc-gen-go-grpc
out: pb
opt:
- paths=source_relative
- local: protoc-gen-go-grpc
out: ../../bsm-sdk/client/golang/feed
opt:
- paths=source_relative
- local: protoc-gen-grpc-gateway
out: pb
opt:
- paths=source_relative
- generate_unbound_methods=True
- local: protoc-gen-slc
out: ./
- local: protoc-gen-ts
out: ../../bsm-sdk/client/typescript
- local: protoc-gen-dart
out: ../../bsm-sdk/client/dart/feed
opt:
- grpc
- local: protoc-gen-openapiv2
out: ./swagger
opt: allow_merge=true,merge_file_name=feed
- local: protoc-gen-openapiv2
out: ../../bsm-sdk/client/docs/feed
opt: allow_merge=true,merge_file_name=feed
- local: protoc-gen-markdown
out: ../../bsm-sdk/client/docs/feed

10
apps/social/feed/buf.yaml Normal file
View File

@@ -0,0 +1,10 @@
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2
lint:
use:
- STANDARD
modules:
- path: proto
breaking:
use:
- FILE

View File

@@ -0,0 +1,12 @@
package main
import (
"fmt"
"git.apinb.com/bsm-social/feed/internal/config"
)
func main() {
config.New("feed")
fmt.Println(config.Spec.Databases)
}

View File

@@ -0,0 +1,45 @@
/**
* @Author: david.yan(david.yan@qq.com)
* @Date: 2021-11-26 15:25:03
*/
package main
import (
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-social/feed/internal/config"
"git.apinb.com/bsm-social/feed/internal/impl"
"git.apinb.com/bsm-social/feed/internal/models"
"git.apinb.com/bsm-social/feed/internal/server"
)
var (
ServiceKey = "Feed"
)
func main() {
config.New(ServiceKey)
impl.NewImpl()
// 初始化服务
s := server.New(config.Spec.Addr)
srv := service.New(
s.Grpc,
&service.Options{
Addr: config.Spec.Addr,
MsConf: config.Spec.MicroService,
EtcdClient: impl.EtcdService,
GatewayCtx: s.Ctx,
GatewayConf: config.Spec.Gateway,
GatewayMux: s.Mux,
},
)
// 注册:初始化数据
srv.Use(models.InitData)
// 停止服务
defer srv.Stop()
// 启动服务
srv.Start()
}

View File

@@ -0,0 +1,45 @@
Name: {ServiceKey}
ListenOn: 0.0.0.0:12212
Dsn: postgres://postgres:CHANGE_ME@47.108.57.74:5432/milu?sslmode=disable&TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
# DB库设置例redis://null:Weidong1214@139.159.232.50:6379/12代表DB12
# Cache: redis://null:YouMake!*@139.159.232.50:6379/
#Etcd:
# Hosts:
# - 127.0.0.1:2379
# Key: service.{Workspace}.{ServiceKey}.rpc
# 匿名访问清单,自动注入网关层
Anonymous:
Key: anonymous.{Workspace}
Urls:
- pb.Check.Hello
# 日志记录
Log:
ServiceName: {ServiceKey}
Mode: file
Path: logs/{ServiceKey}
Stat: false
# 性能监控
Prometheus:
Host: 127.0.0.1
Port: 22212
Path: /metrics
# 链路追踪
Telemetry:
Name: {Workspace}.{ServiceKey}.{RuntimeMode}
Endpoint: http://139.159.232.50:14268/api/traces
Sampler: 1.0
Batcher: jaeger
# MQ Pulsar
#Pulsar:
# Endpoints: 127.0.0.1
# Token: 9091
# Namespaces: {Workspace}

View File

@@ -0,0 +1,44 @@
Name: {ServiceKey}
ListenOn: 0.0.0.0:12212
Dsn: postgres://prod:MakeW2023~PROD@192.168.0.224:5432/scf?sslmode=disable&TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
Cache: redis://null:CHANGE_ME@192.168.0.43:6379/
Etcd:
Hosts:
- 192.168.0.83:2379
Key: service.{Workspace}.{ServiceKey}.rpc
# 匿名访问清单,自动注入网关层
Anonymous:
Key: anonymous.{Workspace}
Urls:
- initialize.Check.Hello
# 日志记录
Log:
ServiceName: {ServiceKey}
Mode: file
Path: logs/{ServiceKey}
Stat: false
# 性能监控
Prometheus:
Host: 127.0.0.1
Port: 22212
Path: /metrics
# 链路追踪
Telemetry:
Name: {Workspace}.{ServiceKey}.{RuntimeMode}
Endpoint: http://139.159.232.50:14268/api/traces
Sampler: 1.0
Batcher: jaeger
# MQ Pulsar
#Pulsar:
# Endpoints: 127.0.0.1
# Token: 9091
# Namespaces: {Workspace}

View File

@@ -0,0 +1,45 @@
Name: {ServiceKey}
ListenOn: 0.0.0.0:12212
Dsn: postgres://postgres:CHANGE_ME@47.108.57.74:5432/milu?sslmode=disable&TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
# DB库设置例redis://null:Weidong1214@139.159.232.50:6379/12代表DB12
Cache: redis://null:CHANGE_ME@127.0.0.1:6379/
Etcd:
Hosts:
- 127.0.0.1:2379
Key: service.{Workspace}.{ServiceKey}.rpc
# 匿名访问清单,自动注入网关层
Anonymous:
Key: anonymous.{Workspace}
Urls:
- pb.Check.Hello
# 日志记录
Log:
ServiceName: {ServiceKey}
Mode: file
Path: logs/{ServiceKey}
Stat: false
# 性能监控
Prometheus:
Host: 127.0.0.1
Port: 22212
Path: /metrics
# 链路追踪
Telemetry:
Name: {Workspace}.{ServiceKey}.{RuntimeMode}
Endpoint: http://139.159.232.50:14268/api/traces
Sampler: 1.0
Batcher: jaeger
# MQ Pulsar
#Pulsar:
# Endpoints: 127.0.0.1
# Token: 9091
# Namespaces: {Workspace}

View File

@@ -0,0 +1,52 @@
Service: feed
Port: 12426
Databases:
Driver: postgres
Source:
- host=47.109.77.183 user=postgres password=CHANGE_ME dbname=bsm_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
Cache: redis://null:CHANGE_ME@47.109.77.183:6379/
# 微服务设置
MicroService:
Enable: false
Anonymous:
- feed.ping.hello
# 微信设置
WeChatConf:
AppID: 123
AppSecret: 123
# KYC认证配置
Kyc:
Provider: jumio
BaseUrl: 123
ApiSecret: 123
ApiToken: 123
ApiArgs: 123
# Gateway 设置
Gateway:
Enable: true
Port: 12425
# 微服务调用密钥
SecretKey: 6ad9529688041483f458f8de11ed16ff
Token:
Prefix: "/token/"
Expire: 86400
# Rpc:
# fts:
# Endpoint: https://api-v2.traingo.cn/fts/v2
# SecretKey: 4ef05311358cd1c8f787281f08b38b1c
# 链路追踪,性能监控,日志收集
# APM:
# Platform: elasticAPM
# Endpoint: http://127.0.0.1:14268/api/traces

View File

@@ -0,0 +1,58 @@
Service: feed
Port: 12426
Databases:
Driver: postgres
Source:
- host=47.109.77.183 user=postgres password=CHANGE_ME dbname=bsm_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
Cache: redis://null:CHANGE_ME@47.109.77.183:6379/
# 微服务设置
MicroService:
Enable: false
Anonymous:
- feed.ping.hello
# 微信设置
WeChatConf:
AppID: 123
AppSecret: 123
# KYC认证配置
Kyc:
Provider: jumio
BaseUrl: 123
ApiSecret: 123
ApiToken: 123
ApiArgs: 123
# KYC认证配置
KycConf:
BaseUrl: 123
ApiSecret: 123
ApiToken: 123
# Gateway 设置
Gateway:
Enable: true
Port: 12425
# 微服务调用密钥
SecretKey: 6ad9529688041483f458f8de11ed16ff
Token:
Prefix: "/token/"
Expire: 86400
# Rpc:
# fts:
# Endpoint: https://api-v2.traingo.cn/fts/v2
# SecretKey: 4ef05311358cd1c8f787281f08b38b1c
# 链路追踪,性能监控,日志收集
# APM:
# Platform: elasticAPM
# Endpoint: http://127.0.0.1:14268/api/traces

View File

@@ -0,0 +1,52 @@
Service: feed
Port: 12426
Databases:
Driver: postgres
Source:
- host=47.109.77.183 user=postgres password=CHANGE_ME dbname=bsm_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
Cache: redis://null:CHANGE_ME@47.109.77.183:6379/
# 微服务设置
MicroService:
Enable: false
Anonymous:
- feed.ping.hello
# 微信设置
WeChatConf:
AppID: 123
AppSecret: 123
# KYC认证配置
Kyc:
Provider: jumio
BaseUrl: 123
ApiSecret: 123
ApiToken: 123
ApiArgs: 123
# Gateway 设置
Gateway:
Enable: true
Port: 12425
# 微服务调用密钥
SecretKey: 6ad9529688041483f458f8de11ed16ff
Token:
Prefix: "/token/"
Expire: 86400
# Rpc:
# fts:
# Endpoint: https://api-v2.traingo.cn/fts/v2
# SecretKey: 4ef05311358cd1c8f787281f08b38b1c
# 链路追踪,性能监控,日志收集
# APM:
# Platform: elasticAPM
# Endpoint: http://127.0.0.1:14268/api/traces

View File

@@ -0,0 +1,8 @@
[program:bsm-apps-feed]
command=/data/app/bsm-apps-feed
directory=/data/app
autostart=true
autorestart=true
user=root
redirect_stderr=true
stdout_logfile=/data/app/logs/apps-feed.log

50
apps/social/feed/go.mod Normal file
View File

@@ -0,0 +1,50 @@
module git.apinb.com/bsm-social/feed
go 1.26.5
require (
git.apinb.com/bsm-sdk/core v0.2.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0
github.com/patrickmn/go-cache v2.1.0+incompatible
go.etcd.io/etcd/client/v3 v3.6.12
google.golang.org/grpc v1.81.1
google.golang.org/protobuf v1.36.11
gorm.io/gorm v1.31.1
)
require (
filippo.io/edwards25519 v1.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.7.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-sql-driver/mysql v1.10.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.10.0 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/oklog/ulid/v2 v2.1.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/redis/go-redis/v9 v9.20.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
go.etcd.io/etcd/api/v3 v3.6.12 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.6.12 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.28.0 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/text v0.37.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.6.0 // indirect
gorm.io/driver/postgres v1.6.0 // indirect
)

161
apps/social/feed/go.sum Normal file
View File

@@ -0,0 +1,161 @@
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
git.apinb.com/bsm-sdk/core v0.2.0 h1:/e9yqpsbKBrRgMiGpS3KX2O4qDLxo5V5GpPSLNGxEKw=
git.apinb.com/bsm-sdk/core v0.2.0/go.mod h1:E9T6Eboo/0Zb36BjkKbIgvFzq4fQ2Q8P/7y5zmYTI6Y=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/coreos/go-systemd/v22 v22.7.0 h1:LAEzFkke61DFROc7zNLX/WA2i5J8gYqe0rSj9KI28KA=
github.com/coreos/go-systemd/v22 v22.7.0/go.mod h1:xNUYtjHu2EDXbsxz1i41wouACIwT7Ybq9o0BQhMwD0w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw=
github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.10.0 h1:VhSvgU2jSli8o3AqIEOTJr7rZwAEUVo4E4XhR94Zfr0=
github.com/jackc/pgx/v5 v5.10.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.20.0 h1:WnQYxLkgO2xiXTCJY0ldIiI8dNqCDlQAG+AtaH7a2a0=
github.com/redis/go-redis/v9 v9.20.0/go.mod h1:v/M13XI1PVCDcm01VtPFOADfZtHf8YW3baQf57KlIkA=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
go.etcd.io/etcd/api/v3 v3.6.12 h1:OLOZUKEuAA36TR48F0cIaa8FdzrWygjyfrJxXg4iDgs=
go.etcd.io/etcd/api/v3 v3.6.12/go.mod h1:p14EIQXHbuOQbVvL/WEes5uqKnxP9AgKJgpjbMVvzvE=
go.etcd.io/etcd/client/pkg/v3 v3.6.12 h1:36zzB+pQOdHbhN+kH2iJz/K8bJn0ZLtLfPPO7jozTDo=
go.etcd.io/etcd/client/pkg/v3 v3.6.12/go.mod h1:hh2+ZXtfLzs3o6mn92ntgNPBrTJJOvXqICM5g3L3DMY=
go.etcd.io/etcd/client/v3 v3.6.12 h1:kMSP6JcPZMqSJiX+TXdUIBU/4eXEZWBAaui4VihMbIc=
go.etcd.io/etcd/client/v3 v3.6.12/go.mod h1:CMs6fJWYiZQk4ytFjd4lE1diOvvRMmtbbn/alZXd3dQ=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw=
go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A=
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa h1:Kjn0N0tCrDgiAFW+lGO4JZ3ck44CehvJQMAwj9QF0G8=
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:q4lMZS6kskjT5HvCPrnnypcDPVJqT/f4nfxmkE7gryY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ=
google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4=
gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo=
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=

View File

@@ -0,0 +1,62 @@
package config
import (
"net"
"git.apinb.com/bsm-sdk/core/conf"
"git.apinb.com/bsm-sdk/core/crypto/encipher"
"git.apinb.com/bsm-sdk/core/env"
)
var (
Spec SrvConfig
)
type SrvConfig struct {
conf.Base `yaml:",inline"`
Databases *conf.DBConf `yaml:"Databases"`
MicroService *conf.MicroServiceConf `yaml:"MicroService"`
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
Gateway *conf.GatewayConf `yaml:"Gateway"`
Apm *conf.ApmConf `yaml:"APM"`
Etcd *conf.EtcdConf `yaml:"Etcd"`
WeChat *WeChatConf `yaml:"WeChatConf"`
Token *TokenConf `yaml:"Token"`
Kyc *KycConf `yaml:"Kyc"`
}
type KycConf struct {
Provider string `yaml:"Provider"`
BaseUrl string `yaml:"BaseUrl"`
ApiSecret string `yaml:"ApiSecret"`
ApiToken string `yaml:"ApiToken"`
ApiArgs string `yaml:"ApiArgs"`
}
type TokenConf struct {
Prefix string `yaml:"Prefix"`
Expire int `yaml:"Expire"`
}
type WeChatConf struct {
AppID string `json:"app_id"`
AppSecret string `json:"app_secret"`
}
func New(srvKey string) {
// 初始化配置 创建一个新的配置实例,用于服务配置
conf.New(srvKey, &Spec)
// 配置校验 服务IP,端口; 端口如果不合规,则随机分配端口
Spec.Port = conf.CheckPort(Spec.Port)
Spec.BindIP = conf.CheckIP(Spec.BindIP)
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
// 配置校验 服务名称地址及监听地址不能为空
conf.NotNil(Spec.Service, Spec.Cache)
// 初始化加密SecretKey
encipher.New(env.Runtime.JwtSecretKey)
conf.PrintInfo(Spec.Addr)
}

View File

@@ -0,0 +1,25 @@
package impl
import (
"git.apinb.com/bsm-sdk/core/cache/redis"
"git.apinb.com/bsm-sdk/core/with"
"git.apinb.com/bsm-social/feed/internal/config"
cache "github.com/patrickmn/go-cache"
clientv3 "go.etcd.io/etcd/client/v3"
"gorm.io/gorm"
)
var (
RedisService *redis.RedisClient
EtcdService *clientv3.Client
DBService *gorm.DB
MemorySerice *cache.Cache
)
func NewImpl() {
// with activating
MemorySerice = with.Memory(nil)
RedisService = with.RedisCache(config.Spec.Cache) // redis cache
DBService = with.Databases(config.Spec.Databases, nil) // model
EtcdService = with.Etcd(config.Spec.Etcd) // etcd
}

View File

@@ -0,0 +1,34 @@
package post
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 计数操作
func Action(ctx context.Context, in *pb.PostActionRequest) (reply *pb.StatusReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.GetActionOp() == "" || in.GetActionType() == "" || in.GetIdentity() == "" {
return nil, errcode.ErrInvalidArgument
}
if err := models.LikeAction(in.ActionOp, in.ActionType, in.Identity); err != nil {
printer.Error(err.Error())
return nil, err
}
return &pb.StatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixNano(),
}, nil
}

View File

@@ -0,0 +1,40 @@
package post
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/types"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 新建评论
func AddComment(ctx context.Context, in *pb.CommentItem) (reply *pb.StatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
var data = &models.FeedComment{
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID()},
PostIdentity: in.PostIdentity,
Content: in.Content,
}
if in.Identity != "" {
data.ParentIdentity = in.Identity
}
if err := models.AddComment(data, auth.Identity); err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: data.Identity,
Timeseq: time.Now().UnixNano(),
}, nil
}

View File

@@ -0,0 +1,50 @@
package post
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/types"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 修改推文
func Change(ctx context.Context, in *pb.PostItem) (reply *pb.StatusReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.GetContent() == "" || in.Identity == "" {
return nil, errcode.ErrInvalidArgument
}
var postData = models.FeedPost{
Std_IICUDS: types.Std_IICUDS{Identity: in.Identity},
Content: in.Content,
IsOpen: in.IsOpen,
}
if len(in.GetAttachs()) != 0 {
for _, val := range in.Attachs {
postData.Attachs = append(postData.Attachs, models.FeedRelateAttach{
Identity: utils.UUID(),
AttachType: val.AttachType,
Url: val.Url,
})
}
}
err = models.ChargePost(&postData)
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: postData.Identity,
Timeseq: time.Now().UnixNano(),
}, nil
}

View File

@@ -0,0 +1,29 @@
package post
import (
"context"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 评论列表
func CommentList(ctx context.Context, in *pb.FetchRequest) (reply *pb.CommentListReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// valildate request page_no,page_size.
if in.GetPageNo() < 1 {
in.PageNo = 1
}
if in.GetPageSize() < 10 {
in.PageSize = 50
}
// TODO: add your logic code & delete this line.
return
}

View File

@@ -0,0 +1,62 @@
package post
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/types"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 新建推文
func Create(ctx context.Context, in *pb.PostItem) (reply *pb.StatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.GetContent() == "" {
return nil, errcode.ErrInvalidArgument
}
var postData = models.FeedPost{
Std_IICUDS: types.Std_IICUDS{Identity: utils.UUID()},
Std_Passport: types.Std_Passport{PassportID: auth.ID, PassportIdentity: auth.Identity},
Content: in.Content,
IsOpen: in.IsOpen,
}
if len(in.GetAttachs()) > 0 {
for _, val := range in.Attachs {
postData.Attachs = append(postData.Attachs, models.FeedRelateAttach{
PostIdentity: postData.Std_IICUDS.Identity,
Identity: utils.UUID(),
AttachType: val.AttachType,
Url: val.Url,
})
}
}
if len(in.GetTags()) > 0 {
for _, val := range in.Tags {
postData.Tags = append(postData.Tags, models.FeedRelateTags{
PostIdentity: postData.Std_IICUDS.Identity,
Content: val.Content,
Key: val.Key,
})
}
}
err = models.CreatePost(&postData)
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: postData.Identity,
Timeseq: time.Now().UnixNano(),
}, nil
}

View File

@@ -0,0 +1,34 @@
package post
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 删除评论
func DeleteComment(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.GetId() == 0 && in.GetIdentity() == "" {
return nil, errcode.ErrInvalidArgument
}
err = models.DeleteComment(in.Identity)
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixNano(),
}, nil
}

View File

@@ -0,0 +1,67 @@
package post
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 推文列表
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.PostListReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.GetPageNo() <= 0 {
in.PageNo = 1
}
if in.GetPageSize() <= 0 {
in.PageSize = 10
}
data, cnt, err := models.PostList(in.PageNo, in.PageSize, in.Params["key"])
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
var res = &pb.PostListReply{Cnt: cnt}
if cnt > 0 {
res.List = AssembleList(data)
}
return res, nil
}
func AssembleList(data []*models.FeedPost) (res []*pb.PostItem) {
for _, val := range data {
post := &pb.PostItem{
Identity: val.Identity,
Content: val.Content,
FeedIdentity: val.Identity,
FeedId: int64(val.ID),
IsOpen: val.IsOpen,
CntUnlike: val.CntUnlike,
CntLike: val.CntLike,
CntComment: val.CntComment,
}
for _, tag := range val.Tags {
post.Tags = append(post.Tags, &pb.TagItem{
Key: tag.Key,
Content: tag.Content,
})
}
for _, attachs := range val.Attachs {
post.Attachs = append(post.Attachs, &pb.AttachItem{
Identity: attachs.Identity,
AttachType: attachs.AttachType,
Url: attachs.Url,
})
}
res = append(res, post)
}
return
}

View File

@@ -0,0 +1,36 @@
package post
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 删除推文
func Remove(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.GetIdentity() == "" {
return nil, errcode.ErrInvalidArgument
}
err = models.DeletePost(in.Identity)
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixNano(),
}, nil
}

View File

@@ -0,0 +1,23 @@
package setting
import (
"context"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 修改个人信息
func Info(ctx context.Context, in *pb.Empty) (reply *pb.Empty, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// TODO: valid code
// TODO: add your logic code & delete this line.
return
}

View File

@@ -0,0 +1,23 @@
package setting
import (
"context"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 修改权限信息
func Rights(ctx context.Context, in *pb.Empty) (reply *pb.Empty, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// TODO: valid code
// TODO: add your logic code & delete this line.
return
}

View File

@@ -0,0 +1,37 @@
package tag
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 新建标签
func Create(ctx context.Context, in *pb.AddTagRequest) (reply *pb.StatusReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if len(in.GetTags()) == 0 {
return nil, errcode.ErrInvalidArgument
}
var tags = &[]models.FeedTags{}
for _, val := range in.Tags {
*tags = append(*tags, models.FeedTags{
Key: utils.UUID(),
Content: val,
})
}
if err := models.AddTags(tags); err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{}, nil
}

View File

@@ -0,0 +1,33 @@
package tag
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-social/feed/internal/models"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 标签列表
func List(ctx context.Context, in *pb.FetchRequest) (reply *pb.TagListReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
tags, cnt, err := models.TagsList()
if err != nil {
return nil, errcode.ErrDB
}
var res = &pb.TagListReply{Total: cnt}
for _, v := range tags {
res.Tags = append(res.Tags, &pb.TagItem{
Key: v.Key,
Content: v.Content,
})
}
return &pb.TagListReply{}, nil
}

View File

@@ -0,0 +1,29 @@
package tag
import (
"context"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 话题相关的文章
func PostList(ctx context.Context, in *pb.FetchRequest) (reply *pb.PostListReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// valildate request page_no,page_size.
if in.GetPageNo() < 1 {
in.PageNo = 1
}
if in.GetPageSize() < 10 {
in.PageSize = 50
}
// TODO: add your logic code & delete this line.
return
}

View File

@@ -0,0 +1,29 @@
package timeline
import (
"context"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 关注的动态
func Follow(ctx context.Context, in *pb.FetchRequest) (reply *pb.PostListReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// valildate request page_no,page_size.
if in.GetPageNo() < 1 {
in.PageNo = 1
}
if in.GetPageSize() < 10 {
in.PageSize = 50
}
// TODO: add your logic code & delete this line.
return
}

View File

@@ -0,0 +1,29 @@
package timeline
import (
"context"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 好友动态
func Friend(ctx context.Context, in *pb.FetchRequest) (reply *pb.PostListReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// valildate request page_no,page_size.
if in.GetPageNo() < 1 {
in.PageNo = 1
}
if in.GetPageSize() < 10 {
in.PageSize = 50
}
// TODO: add your logic code & delete this line.
return
}

View File

@@ -0,0 +1,29 @@
package timeline
import (
"context"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 热门
func Hot(ctx context.Context, in *pb.FetchRequest) (reply *pb.PostListReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// valildate request page_no,page_size.
if in.GetPageNo() < 1 {
in.PageNo = 1
}
if in.GetPageSize() < 10 {
in.PageSize = 50
}
// TODO: add your logic code & delete this line.
return
}

View File

@@ -0,0 +1,29 @@
package timeline
import (
"context"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/feed/pb"
)
// 推荐
func Recommend(ctx context.Context, in *pb.FetchRequest) (reply *pb.PostListReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// valildate request page_no,page_size.
if in.GetPageNo() < 1 {
in.PageNo = 1
}
if in.GetPageSize() < 10 {
in.PageSize = 50
}
// TODO: add your logic code & delete this line.
return
}

View File

@@ -0,0 +1,20 @@
package models
import "git.apinb.com/bsm-sdk/core/types"
// feed评论表
type FeedComment struct {
types.Std_IICUDS
types.Std_Passport
PostIdentity string `gorm:"column:post_identity;type:varchar(36);index;" json:"post_identity"` // 推文唯一码
ParentIdentity string `gorm:"column:parent_identity;type:varchar(36);index;" json:"parent_identity"` // 上级评论唯一码
Content string `gorm:"column:content;type:text;default:'';" json:"content"` // 正文
SubComment []FeedComment `gorm:"foreignkey:parent_identity;"` // 子评论唯一码
CntLike int64 `gorm:"column:cnt_like;type:int;default:0" json:"cnt_like"` // 点赞数
CntUnlike int64 `gorm:"column:cnt_unlike;type:int;default:0" json:"cnt_unlike"` // 点踩数
CntComment int64 `gorm:"column:cnt_comment;type:int;default:0" json:"cnt_comment"` // 评论数
}
func (table *FeedComment) TableName() string {
return "feed_comment"
}

View File

@@ -0,0 +1,22 @@
package models
import (
"git.apinb.com/bsm-sdk/core/types"
)
// feed推文表
type FeedPost struct {
types.Std_IICUDS
types.Std_Passport
Content string `gorm:"column:content;type:text;default:'';" json:"content"` // 正文
IsOpen bool `gorm:"column:is_open;default:true;" json:"is_open"` // 默认为true-公开false-不公开
CntLike int64 `gorm:"column:cnt_like;type:int;default:0;" json:"cnt_like"` // 点赞数
CntUnlike int64 `gorm:"column:cnt_unlike;type:int;default:0;" json:"cnt_unlike"` // 点踩数
CntComment int64 `gorm:"column:cnt_comment;type:int;default:0;" json:"cnt_comment"` // 评论数
Attachs []FeedRelateAttach `gorm:"-"`
Tags []FeedRelateTags `gorm:"-"`
}
func (c *FeedPost) TableName() string {
return "feed_post"
}

View File

@@ -0,0 +1,16 @@
package models
import "git.apinb.com/bsm-sdk/core/types"
// feed 关联附件表
type FeedRelateAttach struct {
types.Std_IDIdentity
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;"`
PostIdentity string `gorm:"column:post_identity;type:varchar(36);index;" json:"post_identity"` // 推文唯一码
AttachType string `gorm:"column:attach_type;type:varchar(36);index;" json:"attach_type"` // 附件类型
Url string `gorm:"column:url;type:varchar(255);index;" json:"url"` // 附件地址
}
func (table *FeedRelateAttach) TableName() string {
return "feed_relate_attach"
}

View File

@@ -0,0 +1,15 @@
package models
import "git.apinb.com/bsm-sdk/core/types"
// feed 关联标签表
type FeedRelateTags struct {
types.Std_IDIdentity
PostIdentity string `gorm:"column:post_identity;type:varchar(36);index;" json:"post_identity"`
Key string `gorm:"column:key;type:varchar(36);index;" json:"key"`
Content string `gorm:"-"`
}
func (table *FeedRelateTags) TableName() string {
return "feed_relate_tags"
}

View File

@@ -0,0 +1,16 @@
package models
import (
"gorm.io/gorm"
)
// feed标签表
type FeedTags struct {
gorm.Model
Key string `gorm:"column:key;type:varchar(36);not null" json:"key"`
Content string `gorm:"column:content;type:varchar(255);not null" json:"content"`
}
func (c *FeedTags) TableName() string {
return "feed_tags"
}

View File

@@ -0,0 +1,125 @@
package models
import (
"fmt"
"git.apinb.com/bsm-social/feed/internal/impl"
"gorm.io/gorm"
)
func InitData() error {
return nil
}
func CreatePost(data *FeedPost) error {
err := impl.DBService.Transaction(func(tx *gorm.DB) error {
if err := tx.Create(&data).Error; err != nil {
return err
}
if err := tx.Create(&data.Attachs).Error; err != nil {
return err
}
if err := tx.Create(&data.Tags).Error; err != nil {
return err
}
return nil
})
return err
}
func ChargePost(data *FeedPost) error {
err := impl.DBService.Where("identity = ?", data.Identity).Updates(&data).Error
return err
}
func DeletePost(identity string) error {
err := impl.DBService.Where("identity = ?", identity).Delete(&FeedPost{}).Error
return err
}
// 点赞/踩操作
func LikeAction(action_op, action_type, identity string) (err error) {
var column string
tx := impl.DBService
if action_type == "post" {
tx = tx.Model(&FeedPost{})
} else if action_type == "comment" {
tx = tx.Model(&FeedComment{})
}
if action_op == "ilike" {
column = "cnt_like"
} else if action_type == "unlike" {
column = "cnt_unlike"
}
if err = tx.Where("identity = ?", identity).UpdateColumn(column, gorm.Expr(fmt.Sprintf("%s + ?", column), 1)).Error; err != nil {
return err
}
return
}
// PostList
func PostList(page, size int64, tag string) (list []*FeedPost, cnt int64, err error) {
tx := impl.DBService.Order("created_at desc")
if tag != "" {
tx = tx.Joins("join feed_relate_tags on feed_relate_tags.post_identity = feed_post.identity", impl.DBService.Where(&FeedRelateTags{Key: tag}))
tx = tx.Where("key = ?", tag)
}
tx.Limit(int(page)).Offset(int((page - 1) * size))
err = tx.Find(&list).Count(&cnt).Error
fmt.Print("posts", list)
return
}
func AddTags(data *[]FeedTags) (err error) {
err = impl.DBService.Create(data).Error
if err != nil {
return err
}
return err
}
func ModifyTags(data *FeedTags) (err error) {
err = impl.DBService.Where("identity = ?", data.Key).Save(data).Error
if err != nil {
return err
}
return err
}
func DeleteTags(key string) (err error) {
err = impl.DBService.Where("identity = ?", key).Delete(&FeedTags{}).Error
if err != nil {
return err
}
return err
}
func TagsList() (list []*FeedTags, cnt int64, err error) {
tags := make([]*FeedTags, 0)
tx := impl.DBService.Order("created_at desc")
err = tx.Find(&tags).Count(&cnt).Error
return tags, cnt, err
}
func AddComment(comment *FeedComment, authorIdentity string) (err error) {
err = impl.DBService.Transaction(func(tx *gorm.DB) error {
// 添加评论,更新文章评论量
err := tx.Create(comment).Table("feed_post").Where("identity = ?", comment.PostIdentity).UpdateColumn("cnt_comment", gorm.Expr("cnt_comment + ?", 1)).Error
if err != nil {
return err
}
if comment.ParentIdentity != "" {
//更新被评论的评论数
err = tx.Where("identity = ?", comment.ParentIdentity).UpdateColumn("cnt_comment", gorm.Expr("cnt_comment + ?", 1)).Error
if err != nil {
return err
}
}
return nil
})
return
}
func DeleteComment(identity string) (err error) {
return
}

View File

@@ -0,0 +1,77 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"git.apinb.com/bsm-sdk/core/vars"
pb "git.apinb.com/bsm-social/feed/pb"
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"google.golang.org/protobuf/proto"
"net/http"
"os"
"strings"
)
type Server struct {
Grpc *grpc.Server
Ctx context.Context
Mux *gwRuntime.ServeMux
}
func New(addr string) *Server {
srv := &Server{Ctx: context.Background(), Grpc: grpc.NewServer(), Mux: gwRuntime.NewServeMux(
gwRuntime.WithForwardResponseRewriter(responseEnvelope),
)}
// register service to grpc.Server
pb.RegisterPostServer(srv.Grpc, NewPostServer())
pb.RegisterSettingServer(srv.Grpc, NewSettingServer())
pb.RegisterTagServer(srv.Grpc, NewTagServer())
pb.RegisterTimelineServer(srv.Grpc, NewTimelineServer())
reflection.Register(srv.Grpc)
// 将服务注册到Gateway
opts := []grpc.DialOption{grpc.WithInsecure()}
pb.RegisterPostHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterSettingHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterTagHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
pb.RegisterTimelineHandlerFromEndpoint(srv.Ctx, srv.Mux, addr, opts)
// Register services swagger
srv.RegisterSwagger()
return srv
}
// RegisterSwagger 注册swagger
func (s *Server) RegisterSwagger() {
srvKey := strings.ToLower(vars.ServiceKey)
s.Mux.HandlePath("GET", "/"+srvKey+".swagger.json", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
w.Header().Set("Content-Type", "application/json")
bytes, err := os.ReadFile("./swagger/" + srvKey + ".swagger.json")
if err != nil {
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(err.Error()))
return
}
w.Write(bytes)
return
})
}
// response envelope
func responseEnvelope(_ context.Context, response proto.Message) (interface{}, error) {
name := string(response.ProtoReflect().Descriptor().Name())
if name == "Status" || name == "Error" || name == "StatusReply" {
return response, nil
}
return map[string]any{
"code": 0,
"message": "OK",
"result": response,
}, nil
}

View File

@@ -0,0 +1,56 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"git.apinb.com/bsm-social/feed/internal/logic/post"
pb "git.apinb.com/bsm-social/feed/pb"
)
type PostServer struct {
pb.UnimplementedPostServer
}
func NewPostServer() *PostServer {
return &PostServer{}
}
// 推文列表
func (s *PostServer) Fetch(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return post.Fetch(ctx, in)
}
// 新建推文
func (s *PostServer) Create(ctx context.Context, in *pb.PostItem) (*pb.StatusReply, error) {
return post.Create(ctx, in)
}
// 修改推文
func (s *PostServer) Change(ctx context.Context, in *pb.PostItem) (*pb.StatusReply, error) {
return post.Change(ctx, in)
}
// 删除推文
func (s *PostServer) Remove(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
return post.Remove(ctx, in)
}
// 评论列表
func (s *PostServer) CommentList(ctx context.Context, in *pb.FetchRequest) (*pb.CommentListReply, error) {
return post.CommentList(ctx, in)
}
// 新建评论
func (s *PostServer) AddComment(ctx context.Context, in *pb.CommentItem) (*pb.StatusReply, error) {
return post.AddComment(ctx, in)
}
// 删除评论
func (s *PostServer) DeleteComment(ctx context.Context, in *pb.IdentRequest) (*pb.StatusReply, error) {
return post.DeleteComment(ctx, in)
}
// 计数操作
func (s *PostServer) Action(ctx context.Context, in *pb.PostActionRequest) (*pb.StatusReply, error) {
return post.Action(ctx, in)
}

View File

@@ -0,0 +1,26 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"git.apinb.com/bsm-social/feed/internal/logic/setting"
pb "git.apinb.com/bsm-social/feed/pb"
)
type SettingServer struct {
pb.UnimplementedSettingServer
}
func NewSettingServer() *SettingServer {
return &SettingServer{}
}
// 修改个人信息
func (s *SettingServer) Info(ctx context.Context, in *pb.Empty) (*pb.Empty, error) {
return setting.Info(ctx, in)
}
// 修改权限信息
func (s *SettingServer) Rights(ctx context.Context, in *pb.Empty) (*pb.Empty, error) {
return setting.Rights(ctx, in)
}

View File

@@ -0,0 +1,31 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"git.apinb.com/bsm-social/feed/internal/logic/tag"
pb "git.apinb.com/bsm-social/feed/pb"
)
type TagServer struct {
pb.UnimplementedTagServer
}
func NewTagServer() *TagServer {
return &TagServer{}
}
// 标签列表
func (s *TagServer) List(ctx context.Context, in *pb.FetchRequest) (*pb.TagListReply, error) {
return tag.List(ctx, in)
}
// 新建标签
func (s *TagServer) Create(ctx context.Context, in *pb.AddTagRequest) (*pb.StatusReply, error) {
return tag.Create(ctx, in)
}
// 话题相关的文章
func (s *TagServer) PostList(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return tag.PostList(ctx, in)
}

View File

@@ -0,0 +1,36 @@
// Code generated by protoc-gen-slc. DO NOT EDIT.
package server
import (
"context"
"git.apinb.com/bsm-social/feed/internal/logic/timeline"
pb "git.apinb.com/bsm-social/feed/pb"
)
type TimelineServer struct {
pb.UnimplementedTimelineServer
}
func NewTimelineServer() *TimelineServer {
return &TimelineServer{}
}
// 推荐
func (s *TimelineServer) Recommend(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return timeline.Recommend(ctx, in)
}
// 好友动态
func (s *TimelineServer) Friend(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return timeline.Friend(ctx, in)
}
// 关注的动态
func (s *TimelineServer) Follow(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return timeline.Follow(ctx, in)
}
// 热门
func (s *TimelineServer) Hot(ctx context.Context, in *pb.FetchRequest) (*pb.PostListReply, error) {
return timeline.Hot(ctx, in)
}

View File

@@ -0,0 +1,706 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.8
// protoc (unknown)
// source: blocks.proto
package feed
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type FetchRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
PageNo int64 `protobuf:"varint,1,opt,name=page_no,json=pageNo,proto3" json:"page_no,omitempty"` // 页数
PageSize int64 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` // 每页记录数
Params map[string]string `protobuf:"bytes,3,rep,name=params,proto3" json:"params,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` // 条件参数,key=val,eg key:category_id=?,vlaue=11
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *FetchRequest) Reset() {
*x = FetchRequest{}
mi := &file_blocks_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *FetchRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*FetchRequest) ProtoMessage() {}
func (x *FetchRequest) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use FetchRequest.ProtoReflect.Descriptor instead.
func (*FetchRequest) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{0}
}
func (x *FetchRequest) GetPageNo() int64 {
if x != nil {
return x.PageNo
}
return 0
}
func (x *FetchRequest) GetPageSize() int64 {
if x != nil {
return x.PageSize
}
return 0
}
func (x *FetchRequest) GetParams() map[string]string {
if x != nil {
return x.Params
}
return nil
}
type IdentRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // 唯一ID
Identity string `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"` // 唯一码
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *IdentRequest) Reset() {
*x = IdentRequest{}
mi := &file_blocks_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *IdentRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*IdentRequest) ProtoMessage() {}
func (x *IdentRequest) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use IdentRequest.ProtoReflect.Descriptor instead.
func (*IdentRequest) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{1}
}
func (x *IdentRequest) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
func (x *IdentRequest) GetIdentity() string {
if x != nil {
return x.Identity
}
return ""
}
type VersionRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Version int64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` // 时序版本号
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *VersionRequest) Reset() {
*x = VersionRequest{}
mi := &file_blocks_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *VersionRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*VersionRequest) ProtoMessage() {}
func (x *VersionRequest) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use VersionRequest.ProtoReflect.Descriptor instead.
func (*VersionRequest) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{2}
}
func (x *VersionRequest) GetVersion() int64 {
if x != nil {
return x.Version
}
return 0
}
type SearchRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Keyword string `protobuf:"bytes,1,opt,name=keyword,proto3" json:"keyword,omitempty"` //关键词
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SearchRequest) Reset() {
*x = SearchRequest{}
mi := &file_blocks_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SearchRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SearchRequest) ProtoMessage() {}
func (x *SearchRequest) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SearchRequest.ProtoReflect.Descriptor instead.
func (*SearchRequest) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{3}
}
func (x *SearchRequest) GetKeyword() string {
if x != nil {
return x.Keyword
}
return ""
}
type StatusReply struct {
state protoimpl.MessageState `protogen:"open.v1"`
Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` // 数据
Timeseq int64 `protobuf:"varint,2,opt,name=timeseq,proto3" json:"timeseq,omitempty"` // 响应时间序列
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *StatusReply) Reset() {
*x = StatusReply{}
mi := &file_blocks_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *StatusReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*StatusReply) ProtoMessage() {}
func (x *StatusReply) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use StatusReply.ProtoReflect.Descriptor instead.
func (*StatusReply) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{4}
}
func (x *StatusReply) GetData() string {
if x != nil {
return x.Data
}
return ""
}
func (x *StatusReply) GetTimeseq() int64 {
if x != nil {
return x.Timeseq
}
return 0
}
type Empty struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *Empty) Reset() {
*x = Empty{}
mi := &file_blocks_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *Empty) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Empty) ProtoMessage() {}
func (x *Empty) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Empty.ProtoReflect.Descriptor instead.
func (*Empty) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{5}
}
// 推文列表
type PostListReply struct {
state protoimpl.MessageState `protogen:"open.v1"`
List []*PostItem `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"`
Cnt int64 `protobuf:"varint,2,opt,name=cnt,proto3" json:"cnt,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *PostListReply) Reset() {
*x = PostListReply{}
mi := &file_blocks_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *PostListReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PostListReply) ProtoMessage() {}
func (x *PostListReply) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PostListReply.ProtoReflect.Descriptor instead.
func (*PostListReply) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{6}
}
func (x *PostListReply) GetList() []*PostItem {
if x != nil {
return x.List
}
return nil
}
func (x *PostListReply) GetCnt() int64 {
if x != nil {
return x.Cnt
}
return 0
}
// 推文
type PostItem struct {
state protoimpl.MessageState `protogen:"open.v1"`
Identity string `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` // 唯一标识
Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"` // 内容
FeedId int64 `protobuf:"varint,3,opt,name=feed_id,json=feedId,proto3" json:"feed_id,omitempty"` // 通行证ID
FeedIdentity string `protobuf:"bytes,4,opt,name=feed_identity,json=feedIdentity,proto3" json:"feed_identity,omitempty"` // 通行证Identity
IsOpen bool `protobuf:"varint,5,opt,name=is_open,json=isOpen,proto3" json:"is_open,omitempty"` // 是否公开默认为0-公开1-不公开
CntUnlike int64 `protobuf:"varint,6,opt,name=cnt_unlike,json=cntUnlike,proto3" json:"cnt_unlike,omitempty"` // 点踩数量
CntComment int64 `protobuf:"varint,7,opt,name=cnt_comment,json=cntComment,proto3" json:"cnt_comment,omitempty"` // 评论数量
CntLike int64 `protobuf:"varint,8,opt,name=cnt_like,json=cntLike,proto3" json:"cnt_like,omitempty"` // 点赞数量
Attachs []*AttachItem `protobuf:"bytes,9,rep,name=attachs,proto3" json:"attachs,omitempty"` // 附件信息
Tags []*TagItem `protobuf:"bytes,10,rep,name=tags,proto3" json:"tags,omitempty"` // 所属话题
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *PostItem) Reset() {
*x = PostItem{}
mi := &file_blocks_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *PostItem) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PostItem) ProtoMessage() {}
func (x *PostItem) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[7]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PostItem.ProtoReflect.Descriptor instead.
func (*PostItem) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{7}
}
func (x *PostItem) GetIdentity() string {
if x != nil {
return x.Identity
}
return ""
}
func (x *PostItem) GetContent() string {
if x != nil {
return x.Content
}
return ""
}
func (x *PostItem) GetFeedId() int64 {
if x != nil {
return x.FeedId
}
return 0
}
func (x *PostItem) GetFeedIdentity() string {
if x != nil {
return x.FeedIdentity
}
return ""
}
func (x *PostItem) GetIsOpen() bool {
if x != nil {
return x.IsOpen
}
return false
}
func (x *PostItem) GetCntUnlike() int64 {
if x != nil {
return x.CntUnlike
}
return 0
}
func (x *PostItem) GetCntComment() int64 {
if x != nil {
return x.CntComment
}
return 0
}
func (x *PostItem) GetCntLike() int64 {
if x != nil {
return x.CntLike
}
return 0
}
func (x *PostItem) GetAttachs() []*AttachItem {
if x != nil {
return x.Attachs
}
return nil
}
func (x *PostItem) GetTags() []*TagItem {
if x != nil {
return x.Tags
}
return nil
}
// 附件
type AttachItem struct {
state protoimpl.MessageState `protogen:"open.v1"`
Identity string `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` // 唯一标识
AttachType string `protobuf:"bytes,2,opt,name=attach_type,json=attachType,proto3" json:"attach_type,omitempty"` // 文件类型
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"` // 文件路径
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AttachItem) Reset() {
*x = AttachItem{}
mi := &file_blocks_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AttachItem) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AttachItem) ProtoMessage() {}
func (x *AttachItem) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AttachItem.ProtoReflect.Descriptor instead.
func (*AttachItem) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{8}
}
func (x *AttachItem) GetIdentity() string {
if x != nil {
return x.Identity
}
return ""
}
func (x *AttachItem) GetAttachType() string {
if x != nil {
return x.AttachType
}
return ""
}
func (x *AttachItem) GetUrl() string {
if x != nil {
return x.Url
}
return ""
}
// 标签
type TagItem struct {
state protoimpl.MessageState `protogen:"open.v1"`
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` // 标签唯一码
Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"` // 标签内容
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *TagItem) Reset() {
*x = TagItem{}
mi := &file_blocks_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *TagItem) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*TagItem) ProtoMessage() {}
func (x *TagItem) ProtoReflect() protoreflect.Message {
mi := &file_blocks_proto_msgTypes[9]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use TagItem.ProtoReflect.Descriptor instead.
func (*TagItem) Descriptor() ([]byte, []int) {
return file_blocks_proto_rawDescGZIP(), []int{9}
}
func (x *TagItem) GetKey() string {
if x != nil {
return x.Key
}
return ""
}
func (x *TagItem) GetContent() string {
if x != nil {
return x.Content
}
return ""
}
var File_blocks_proto protoreflect.FileDescriptor
const file_blocks_proto_rawDesc = "" +
"\n" +
"\x11feed/blocks.proto\x12\x04feed\"\xb7\x01\n" +
"\fFetchRequest\x12\x17\n" +
"\apage_no\x18\x01 \x01(\x03R\x06pageNo\x12\x1b\n" +
"\tpage_size\x18\x02 \x01(\x03R\bpageSize\x126\n" +
"\x06params\x18\x03 \x03(\v2\x1e.feed.FetchRequest.ParamsEntryR\x06params\x1a9\n" +
"\vParamsEntry\x12\x10\n" +
"\x03key\x18\x01 \x01(\tR\x03key\x12\x14\n" +
"\x05value\x18\x02 \x01(\tR\x05value:\x028\x01\":\n" +
"\fIdentRequest\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x1a\n" +
"\bidentity\x18\x02 \x01(\tR\bidentity\"*\n" +
"\x0eVersionRequest\x12\x18\n" +
"\aversion\x18\x01 \x01(\x03R\aversion\")\n" +
"\rSearchRequest\x12\x18\n" +
"\akeyword\x18\x01 \x01(\tR\akeyword\";\n" +
"\vStatusReply\x12\x12\n" +
"\x04data\x18\x01 \x01(\tR\x04data\x12\x18\n" +
"\atimeseq\x18\x02 \x01(\x03R\atimeseq\"\a\n" +
"\x05Empty\"E\n" +
"\rPostListReply\x12\"\n" +
"\x04list\x18\x01 \x03(\v2\x0e.feed.PostItemR\x04list\x12\x10\n" +
"\x03cnt\x18\x02 \x01(\x03R\x03cnt\"\xc1\x02\n" +
"\bPostItem\x12\x1a\n" +
"\bidentity\x18\x01 \x01(\tR\bidentity\x12\x18\n" +
"\acontent\x18\x02 \x01(\tR\acontent\x12\x17\n" +
"\afeed_id\x18\x03 \x01(\x03R\x06feedId\x12#\n" +
"\rfeed_identity\x18\x04 \x01(\tR\ffeedIdentity\x12\x17\n" +
"\ais_open\x18\x05 \x01(\bR\x06isOpen\x12\x1d\n" +
"\n" +
"cnt_unlike\x18\x06 \x01(\x03R\tcntUnlike\x12\x1f\n" +
"\vcnt_comment\x18\a \x01(\x03R\n" +
"cntComment\x12\x19\n" +
"\bcnt_like\x18\b \x01(\x03R\acntLike\x12*\n" +
"\aattachs\x18\t \x03(\v2\x10.feed.AttachItemR\aattachs\x12!\n" +
"\x04tags\x18\n" +
" \x03(\v2\r.feed.TagItemR\x04tags\"[\n" +
"\n" +
"AttachItem\x12\x1a\n" +
"\bidentity\x18\x01 \x01(\tR\bidentity\x12\x1f\n" +
"\vattach_type\x18\x02 \x01(\tR\n" +
"attachType\x12\x10\n" +
"\x03url\x18\x03 \x01(\tR\x03url\"5\n" +
"\aTagItem\x12\x10\n" +
"\x03key\x18\x01 \x01(\tR\x03key\x12\x18\n" +
"\acontent\x18\x02 \x01(\tR\acontentB\bZ\x06.;feedb\x06proto3"
var (
file_blocks_proto_rawDescOnce sync.Once
file_blocks_proto_rawDescData []byte
)
func file_blocks_proto_rawDescGZIP() []byte {
file_blocks_proto_rawDescOnce.Do(func() {
file_blocks_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_blocks_proto_rawDesc), len(file_blocks_proto_rawDesc)))
})
return file_blocks_proto_rawDescData
}
var file_blocks_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
var file_blocks_proto_goTypes = []any{
(*FetchRequest)(nil), // 0: feed.FetchRequest
(*IdentRequest)(nil), // 1: feed.IdentRequest
(*VersionRequest)(nil), // 2: feed.VersionRequest
(*SearchRequest)(nil), // 3: feed.SearchRequest
(*StatusReply)(nil), // 4: feed.StatusReply
(*Empty)(nil), // 5: feed.Empty
(*PostListReply)(nil), // 6: feed.PostListReply
(*PostItem)(nil), // 7: feed.PostItem
(*AttachItem)(nil), // 8: feed.AttachItem
(*TagItem)(nil), // 9: feed.TagItem
nil, // 10: feed.FetchRequest.ParamsEntry
}
var file_blocks_proto_depIdxs = []int32{
10, // 0: feed.FetchRequest.params:type_name -> feed.FetchRequest.ParamsEntry
7, // 1: feed.PostListReply.list:type_name -> feed.PostItem
8, // 2: feed.PostItem.attachs:type_name -> feed.AttachItem
9, // 3: feed.PostItem.tags:type_name -> feed.TagItem
4, // [4:4] is the sub-list for method output_type
4, // [4:4] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension type_name
4, // [4:4] is the sub-list for extension extendee
0, // [0:4] is the sub-list for field type_name
}
func init() { file_blocks_proto_init() }
func file_blocks_proto_init() {
if File_blocks_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_blocks_proto_rawDesc), len(file_blocks_proto_rawDesc)),
NumEnums: 0,
NumMessages: 11,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_blocks_proto_goTypes,
DependencyIndexes: file_blocks_proto_depIdxs,
MessageInfos: file_blocks_proto_msgTypes,
}.Build()
File_blocks_proto = out.File
file_blocks_proto_goTypes = nil
file_blocks_proto_depIdxs = nil
}

View File

@@ -0,0 +1,317 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.8
// protoc (unknown)
// source: post.proto
package feed
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// 推文评论列表
type CommentListReply struct {
state protoimpl.MessageState `protogen:"open.v1"`
List []*CommentItem `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` // 评论列表
Total int64 `protobuf:"varint,2,opt,name=total,proto3" json:"total,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *CommentListReply) Reset() {
*x = CommentListReply{}
mi := &file_post_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *CommentListReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CommentListReply) ProtoMessage() {}
func (x *CommentListReply) ProtoReflect() protoreflect.Message {
mi := &file_post_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CommentListReply.ProtoReflect.Descriptor instead.
func (*CommentListReply) Descriptor() ([]byte, []int) {
return file_post_proto_rawDescGZIP(), []int{0}
}
func (x *CommentListReply) GetList() []*CommentItem {
if x != nil {
return x.List
}
return nil
}
func (x *CommentListReply) GetTotal() int64 {
if x != nil {
return x.Total
}
return 0
}
type CommentItem struct {
state protoimpl.MessageState `protogen:"open.v1"`
Identity string `protobuf:"bytes,1,opt,name=identity,proto3" json:"identity,omitempty"` // 评论identity
PostIdentity string `protobuf:"bytes,2,opt,name=post_identity,json=postIdentity,proto3" json:"post_identity,omitempty"` // 被评论唯一标识
FeedIdentity string `protobuf:"bytes,3,opt,name=feed_identity,json=feedIdentity,proto3" json:"feed_identity,omitempty"` // 评论人唯一标识
Content string `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"` // 评论内容
SubComment []*CommentItem `protobuf:"bytes,5,rep,name=sub_comment,json=subComment,proto3" json:"sub_comment,omitempty"` // 子评论
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *CommentItem) Reset() {
*x = CommentItem{}
mi := &file_post_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *CommentItem) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CommentItem) ProtoMessage() {}
func (x *CommentItem) ProtoReflect() protoreflect.Message {
mi := &file_post_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CommentItem.ProtoReflect.Descriptor instead.
func (*CommentItem) Descriptor() ([]byte, []int) {
return file_post_proto_rawDescGZIP(), []int{1}
}
func (x *CommentItem) GetIdentity() string {
if x != nil {
return x.Identity
}
return ""
}
func (x *CommentItem) GetPostIdentity() string {
if x != nil {
return x.PostIdentity
}
return ""
}
func (x *CommentItem) GetFeedIdentity() string {
if x != nil {
return x.FeedIdentity
}
return ""
}
func (x *CommentItem) GetContent() string {
if x != nil {
return x.Content
}
return ""
}
func (x *CommentItem) GetSubComment() []*CommentItem {
if x != nil {
return x.SubComment
}
return nil
}
type PostActionRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
ActionOp string `protobuf:"bytes,1,opt,name=action_op,json=actionOp,proto3" json:"action_op,omitempty"` //操作运作ilike,unlike
ActionType string `protobuf:"bytes,2,opt,name=action_type,json=actionType,proto3" json:"action_type,omitempty"` //类别:推文,评论
Identity string `protobuf:"bytes,3,opt,name=identity,proto3" json:"identity,omitempty"` // 唯一标识
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *PostActionRequest) Reset() {
*x = PostActionRequest{}
mi := &file_post_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *PostActionRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PostActionRequest) ProtoMessage() {}
func (x *PostActionRequest) ProtoReflect() protoreflect.Message {
mi := &file_post_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PostActionRequest.ProtoReflect.Descriptor instead.
func (*PostActionRequest) Descriptor() ([]byte, []int) {
return file_post_proto_rawDescGZIP(), []int{2}
}
func (x *PostActionRequest) GetActionOp() string {
if x != nil {
return x.ActionOp
}
return ""
}
func (x *PostActionRequest) GetActionType() string {
if x != nil {
return x.ActionType
}
return ""
}
func (x *PostActionRequest) GetIdentity() string {
if x != nil {
return x.Identity
}
return ""
}
var File_post_proto protoreflect.FileDescriptor
const file_post_proto_rawDesc = "" +
"\n" +
"\x16" +
"social/feed/post.proto\x12\x04feed\x1a\x11feed/blocks.proto\"O\n" +
"\x10CommentListReply\x12%\n" +
"\x04list\x18\x01 \x03(\v2\x11.feed.CommentItemR\x04list\x12\x14\n" +
"\x05total\x18\x02 \x01(\x03R\x05total\"\xc1\x01\n" +
"\vCommentItem\x12\x1a\n" +
"\bidentity\x18\x01 \x01(\tR\bidentity\x12#\n" +
"\rpost_identity\x18\x02 \x01(\tR\fpostIdentity\x12#\n" +
"\rfeed_identity\x18\x03 \x01(\tR\ffeedIdentity\x12\x18\n" +
"\acontent\x18\x04 \x01(\tR\acontent\x122\n" +
"\vsub_comment\x18\x05 \x03(\v2\x11.feed.CommentItemR\n" +
"subComment\"m\n" +
"\x11PostActionRequest\x12\x1b\n" +
"\taction_op\x18\x01 \x01(\tR\bactionOp\x12\x1f\n" +
"\vaction_type\x18\x02 \x01(\tR\n" +
"actionType\x12\x1a\n" +
"\bidentity\x18\x03 \x01(\tR\bidentity2\xb0\x03\n" +
"\x04Post\x122\n" +
"\x05Fetch\x12\x12.feed.FetchRequest\x1a\x13.feed.PostListReply\"\x00\x12-\n" +
"\x06Create\x12\x0e.feed.PostItem\x1a\x11.feed.StatusReply\"\x00\x12-\n" +
"\x06Change\x12\x0e.feed.PostItem\x1a\x11.feed.StatusReply\"\x00\x121\n" +
"\x06Remove\x12\x12.feed.IdentRequest\x1a\x11.feed.StatusReply\"\x00\x12;\n" +
"\vCommentList\x12\x12.feed.FetchRequest\x1a\x16.feed.CommentListReply\"\x00\x124\n" +
"\n" +
"AddComment\x12\x11.feed.CommentItem\x1a\x11.feed.StatusReply\"\x00\x128\n" +
"\rDeleteComment\x12\x12.feed.IdentRequest\x1a\x11.feed.StatusReply\"\x00\x126\n" +
"\x06Action\x12\x17.feed.PostActionRequest\x1a\x11.feed.StatusReply\"\x00B\bZ\x06.;feedb\x06proto3"
var (
file_post_proto_rawDescOnce sync.Once
file_post_proto_rawDescData []byte
)
func file_post_proto_rawDescGZIP() []byte {
file_post_proto_rawDescOnce.Do(func() {
file_post_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_post_proto_rawDesc), len(file_post_proto_rawDesc)))
})
return file_post_proto_rawDescData
}
var file_post_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_post_proto_goTypes = []any{
(*CommentListReply)(nil), // 0: feed.CommentListReply
(*CommentItem)(nil), // 1: feed.CommentItem
(*PostActionRequest)(nil), // 2: feed.PostActionRequest
(*FetchRequest)(nil), // 3: feed.FetchRequest
(*PostItem)(nil), // 4: feed.PostItem
(*IdentRequest)(nil), // 5: feed.IdentRequest
(*PostListReply)(nil), // 6: feed.PostListReply
(*StatusReply)(nil), // 7: feed.StatusReply
}
var file_post_proto_depIdxs = []int32{
1, // 0: feed.CommentListReply.list:type_name -> feed.CommentItem
1, // 1: feed.CommentItem.sub_comment:type_name -> feed.CommentItem
3, // 2: feed.Post.Fetch:input_type -> feed.FetchRequest
4, // 3: feed.Post.Create:input_type -> feed.PostItem
4, // 4: feed.Post.Change:input_type -> feed.PostItem
5, // 5: feed.Post.Remove:input_type -> feed.IdentRequest
3, // 6: feed.Post.CommentList:input_type -> feed.FetchRequest
1, // 7: feed.Post.AddComment:input_type -> feed.CommentItem
5, // 8: feed.Post.DeleteComment:input_type -> feed.IdentRequest
2, // 9: feed.Post.Action:input_type -> feed.PostActionRequest
6, // 10: feed.Post.Fetch:output_type -> feed.PostListReply
7, // 11: feed.Post.Create:output_type -> feed.StatusReply
7, // 12: feed.Post.Change:output_type -> feed.StatusReply
7, // 13: feed.Post.Remove:output_type -> feed.StatusReply
0, // 14: feed.Post.CommentList:output_type -> feed.CommentListReply
7, // 15: feed.Post.AddComment:output_type -> feed.StatusReply
7, // 16: feed.Post.DeleteComment:output_type -> feed.StatusReply
7, // 17: feed.Post.Action:output_type -> feed.StatusReply
10, // [10:18] is the sub-list for method output_type
2, // [2:10] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_post_proto_init() }
func file_post_proto_init() {
if File_post_proto != nil {
return
}
file_blocks_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_post_proto_rawDesc), len(file_post_proto_rawDesc)),
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_post_proto_goTypes,
DependencyIndexes: file_post_proto_depIdxs,
MessageInfos: file_post_proto_msgTypes,
}.Build()
File_post_proto = out.File
file_post_proto_goTypes = nil
file_post_proto_depIdxs = nil
}

View File

@@ -0,0 +1,619 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: post.proto
/*
Package feed is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package feed
import (
"context"
"errors"
"io"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
// Suppress "imported and not used" errors
var (
_ codes.Code
_ io.Reader
_ status.Status
_ = errors.New
_ = runtime.String
_ = utilities.NewDoubleArray
_ = metadata.Join
)
func request_Post_Fetch_0(ctx context.Context, marshaler runtime.Marshaler, client PostClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Fetch(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Post_Fetch_0(ctx context.Context, marshaler runtime.Marshaler, server PostServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Fetch(ctx, &protoReq)
return msg, metadata, err
}
func request_Post_Create_0(ctx context.Context, marshaler runtime.Marshaler, client PostClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq PostItem
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Create(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Post_Create_0(ctx context.Context, marshaler runtime.Marshaler, server PostServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq PostItem
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Create(ctx, &protoReq)
return msg, metadata, err
}
func request_Post_Change_0(ctx context.Context, marshaler runtime.Marshaler, client PostClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq PostItem
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Change(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Post_Change_0(ctx context.Context, marshaler runtime.Marshaler, server PostServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq PostItem
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Change(ctx, &protoReq)
return msg, metadata, err
}
func request_Post_Remove_0(ctx context.Context, marshaler runtime.Marshaler, client PostClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq IdentRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Remove(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Post_Remove_0(ctx context.Context, marshaler runtime.Marshaler, server PostServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq IdentRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Remove(ctx, &protoReq)
return msg, metadata, err
}
func request_Post_CommentList_0(ctx context.Context, marshaler runtime.Marshaler, client PostClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.CommentList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Post_CommentList_0(ctx context.Context, marshaler runtime.Marshaler, server PostServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.CommentList(ctx, &protoReq)
return msg, metadata, err
}
func request_Post_AddComment_0(ctx context.Context, marshaler runtime.Marshaler, client PostClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq CommentItem
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.AddComment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Post_AddComment_0(ctx context.Context, marshaler runtime.Marshaler, server PostServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq CommentItem
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.AddComment(ctx, &protoReq)
return msg, metadata, err
}
func request_Post_DeleteComment_0(ctx context.Context, marshaler runtime.Marshaler, client PostClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq IdentRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.DeleteComment(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Post_DeleteComment_0(ctx context.Context, marshaler runtime.Marshaler, server PostServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq IdentRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.DeleteComment(ctx, &protoReq)
return msg, metadata, err
}
func request_Post_Action_0(ctx context.Context, marshaler runtime.Marshaler, client PostClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq PostActionRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Action(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Post_Action_0(ctx context.Context, marshaler runtime.Marshaler, server PostServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq PostActionRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Action(ctx, &protoReq)
return msg, metadata, err
}
// RegisterPostHandlerServer registers the http handlers for service Post to "mux".
// UnaryRPC :call PostServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterPostHandlerFromEndpoint instead.
// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
func RegisterPostHandlerServer(ctx context.Context, mux *runtime.ServeMux, server PostServer) error {
mux.Handle(http.MethodPost, pattern_Post_Fetch_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Post/Fetch", runtime.WithHTTPPathPattern("/feed.Post/Fetch"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Post_Fetch_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Fetch_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Post/Create", runtime.WithHTTPPathPattern("/feed.Post/Create"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Post_Create_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Create_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_Change_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Post/Change", runtime.WithHTTPPathPattern("/feed.Post/Change"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Post_Change_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Change_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_Remove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Post/Remove", runtime.WithHTTPPathPattern("/feed.Post/Remove"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Post_Remove_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Remove_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_CommentList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Post/CommentList", runtime.WithHTTPPathPattern("/feed.Post/CommentList"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Post_CommentList_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_CommentList_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_AddComment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Post/AddComment", runtime.WithHTTPPathPattern("/feed.Post/AddComment"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Post_AddComment_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_AddComment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_DeleteComment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Post/DeleteComment", runtime.WithHTTPPathPattern("/feed.Post/DeleteComment"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Post_DeleteComment_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_DeleteComment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_Action_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Post/Action", runtime.WithHTTPPathPattern("/feed.Post/Action"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Post_Action_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Action_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterPostHandlerFromEndpoint is same as RegisterPostHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterPostHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.NewClient(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterPostHandler(ctx, mux, conn)
}
// RegisterPostHandler registers the http handlers for service Post to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterPostHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterPostHandlerClient(ctx, mux, NewPostClient(conn))
}
// RegisterPostHandlerClient registers the http handlers for service Post
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "PostClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "PostClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "PostClient" to call the correct interceptors. This client ignores the HTTP middlewares.
func RegisterPostHandlerClient(ctx context.Context, mux *runtime.ServeMux, client PostClient) error {
mux.Handle(http.MethodPost, pattern_Post_Fetch_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Post/Fetch", runtime.WithHTTPPathPattern("/feed.Post/Fetch"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Post_Fetch_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Fetch_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Post/Create", runtime.WithHTTPPathPattern("/feed.Post/Create"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Post_Create_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Create_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_Change_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Post/Change", runtime.WithHTTPPathPattern("/feed.Post/Change"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Post_Change_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Change_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_Remove_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Post/Remove", runtime.WithHTTPPathPattern("/feed.Post/Remove"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Post_Remove_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Remove_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_CommentList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Post/CommentList", runtime.WithHTTPPathPattern("/feed.Post/CommentList"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Post_CommentList_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_CommentList_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_AddComment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Post/AddComment", runtime.WithHTTPPathPattern("/feed.Post/AddComment"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Post_AddComment_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_AddComment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_DeleteComment_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Post/DeleteComment", runtime.WithHTTPPathPattern("/feed.Post/DeleteComment"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Post_DeleteComment_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_DeleteComment_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Post_Action_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Post/Action", runtime.WithHTTPPathPattern("/feed.Post/Action"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Post_Action_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Post_Action_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Post_Fetch_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Post", "Fetch"}, ""))
pattern_Post_Create_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Post", "Create"}, ""))
pattern_Post_Change_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Post", "Change"}, ""))
pattern_Post_Remove_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Post", "Remove"}, ""))
pattern_Post_CommentList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Post", "CommentList"}, ""))
pattern_Post_AddComment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Post", "AddComment"}, ""))
pattern_Post_DeleteComment_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Post", "DeleteComment"}, ""))
pattern_Post_Action_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Post", "Action"}, ""))
)
var (
forward_Post_Fetch_0 = runtime.ForwardResponseMessage
forward_Post_Create_0 = runtime.ForwardResponseMessage
forward_Post_Change_0 = runtime.ForwardResponseMessage
forward_Post_Remove_0 = runtime.ForwardResponseMessage
forward_Post_CommentList_0 = runtime.ForwardResponseMessage
forward_Post_AddComment_0 = runtime.ForwardResponseMessage
forward_Post_DeleteComment_0 = runtime.ForwardResponseMessage
forward_Post_Action_0 = runtime.ForwardResponseMessage
)

View File

@@ -0,0 +1,407 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc (unknown)
// source: post.proto
package feed
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Post_Fetch_FullMethodName = "/feed.Post/Fetch"
Post_Create_FullMethodName = "/feed.Post/Create"
Post_Change_FullMethodName = "/feed.Post/Change"
Post_Remove_FullMethodName = "/feed.Post/Remove"
Post_CommentList_FullMethodName = "/feed.Post/CommentList"
Post_AddComment_FullMethodName = "/feed.Post/AddComment"
Post_DeleteComment_FullMethodName = "/feed.Post/DeleteComment"
Post_Action_FullMethodName = "/feed.Post/Action"
)
// PostClient is the client API for Post service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
//
// 推文相关操作
type PostClient interface {
// 推文列表
Fetch(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error)
// 新建推文
Create(ctx context.Context, in *PostItem, opts ...grpc.CallOption) (*StatusReply, error)
// 修改推文
Change(ctx context.Context, in *PostItem, opts ...grpc.CallOption) (*StatusReply, error)
// 删除推文
Remove(ctx context.Context, in *IdentRequest, opts ...grpc.CallOption) (*StatusReply, error)
// 评论列表
CommentList(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*CommentListReply, error)
// 新建评论
AddComment(ctx context.Context, in *CommentItem, opts ...grpc.CallOption) (*StatusReply, error)
// 删除评论
DeleteComment(ctx context.Context, in *IdentRequest, opts ...grpc.CallOption) (*StatusReply, error)
// 计数操作
Action(ctx context.Context, in *PostActionRequest, opts ...grpc.CallOption) (*StatusReply, error)
}
type postClient struct {
cc grpc.ClientConnInterface
}
func NewPostClient(cc grpc.ClientConnInterface) PostClient {
return &postClient{cc}
}
func (c *postClient) Fetch(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(PostListReply)
err := c.cc.Invoke(ctx, Post_Fetch_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *postClient) Create(ctx context.Context, in *PostItem, opts ...grpc.CallOption) (*StatusReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StatusReply)
err := c.cc.Invoke(ctx, Post_Create_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *postClient) Change(ctx context.Context, in *PostItem, opts ...grpc.CallOption) (*StatusReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StatusReply)
err := c.cc.Invoke(ctx, Post_Change_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *postClient) Remove(ctx context.Context, in *IdentRequest, opts ...grpc.CallOption) (*StatusReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StatusReply)
err := c.cc.Invoke(ctx, Post_Remove_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *postClient) CommentList(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*CommentListReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CommentListReply)
err := c.cc.Invoke(ctx, Post_CommentList_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *postClient) AddComment(ctx context.Context, in *CommentItem, opts ...grpc.CallOption) (*StatusReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StatusReply)
err := c.cc.Invoke(ctx, Post_AddComment_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *postClient) DeleteComment(ctx context.Context, in *IdentRequest, opts ...grpc.CallOption) (*StatusReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StatusReply)
err := c.cc.Invoke(ctx, Post_DeleteComment_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *postClient) Action(ctx context.Context, in *PostActionRequest, opts ...grpc.CallOption) (*StatusReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StatusReply)
err := c.cc.Invoke(ctx, Post_Action_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// PostServer is the server API for Post service.
// All implementations must embed UnimplementedPostServer
// for forward compatibility.
//
// 推文相关操作
type PostServer interface {
// 推文列表
Fetch(context.Context, *FetchRequest) (*PostListReply, error)
// 新建推文
Create(context.Context, *PostItem) (*StatusReply, error)
// 修改推文
Change(context.Context, *PostItem) (*StatusReply, error)
// 删除推文
Remove(context.Context, *IdentRequest) (*StatusReply, error)
// 评论列表
CommentList(context.Context, *FetchRequest) (*CommentListReply, error)
// 新建评论
AddComment(context.Context, *CommentItem) (*StatusReply, error)
// 删除评论
DeleteComment(context.Context, *IdentRequest) (*StatusReply, error)
// 计数操作
Action(context.Context, *PostActionRequest) (*StatusReply, error)
mustEmbedUnimplementedPostServer()
}
// UnimplementedPostServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedPostServer struct{}
func (UnimplementedPostServer) Fetch(context.Context, *FetchRequest) (*PostListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Fetch not implemented")
}
func (UnimplementedPostServer) Create(context.Context, *PostItem) (*StatusReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Create not implemented")
}
func (UnimplementedPostServer) Change(context.Context, *PostItem) (*StatusReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Change not implemented")
}
func (UnimplementedPostServer) Remove(context.Context, *IdentRequest) (*StatusReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Remove not implemented")
}
func (UnimplementedPostServer) CommentList(context.Context, *FetchRequest) (*CommentListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method CommentList not implemented")
}
func (UnimplementedPostServer) AddComment(context.Context, *CommentItem) (*StatusReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method AddComment not implemented")
}
func (UnimplementedPostServer) DeleteComment(context.Context, *IdentRequest) (*StatusReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteComment not implemented")
}
func (UnimplementedPostServer) Action(context.Context, *PostActionRequest) (*StatusReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Action not implemented")
}
func (UnimplementedPostServer) mustEmbedUnimplementedPostServer() {}
func (UnimplementedPostServer) testEmbeddedByValue() {}
// UnsafePostServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to PostServer will
// result in compilation errors.
type UnsafePostServer interface {
mustEmbedUnimplementedPostServer()
}
func RegisterPostServer(s grpc.ServiceRegistrar, srv PostServer) {
// If the following call pancis, it indicates UnimplementedPostServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Post_ServiceDesc, srv)
}
func _Post_Fetch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FetchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PostServer).Fetch(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Post_Fetch_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PostServer).Fetch(ctx, req.(*FetchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Post_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PostItem)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PostServer).Create(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Post_Create_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PostServer).Create(ctx, req.(*PostItem))
}
return interceptor(ctx, in, info, handler)
}
func _Post_Change_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PostItem)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PostServer).Change(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Post_Change_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PostServer).Change(ctx, req.(*PostItem))
}
return interceptor(ctx, in, info, handler)
}
func _Post_Remove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(IdentRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PostServer).Remove(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Post_Remove_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PostServer).Remove(ctx, req.(*IdentRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Post_CommentList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FetchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PostServer).CommentList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Post_CommentList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PostServer).CommentList(ctx, req.(*FetchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Post_AddComment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CommentItem)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PostServer).AddComment(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Post_AddComment_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PostServer).AddComment(ctx, req.(*CommentItem))
}
return interceptor(ctx, in, info, handler)
}
func _Post_DeleteComment_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(IdentRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PostServer).DeleteComment(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Post_DeleteComment_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PostServer).DeleteComment(ctx, req.(*IdentRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Post_Action_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(PostActionRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PostServer).Action(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Post_Action_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PostServer).Action(ctx, req.(*PostActionRequest))
}
return interceptor(ctx, in, info, handler)
}
// Post_ServiceDesc is the grpc.ServiceDesc for Post service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Post_ServiceDesc = grpc.ServiceDesc{
ServiceName: "feed.Post",
HandlerType: (*PostServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Fetch",
Handler: _Post_Fetch_Handler,
},
{
MethodName: "Create",
Handler: _Post_Create_Handler,
},
{
MethodName: "Change",
Handler: _Post_Change_Handler,
},
{
MethodName: "Remove",
Handler: _Post_Remove_Handler,
},
{
MethodName: "CommentList",
Handler: _Post_CommentList_Handler,
},
{
MethodName: "AddComment",
Handler: _Post_AddComment_Handler,
},
{
MethodName: "DeleteComment",
Handler: _Post_DeleteComment_Handler,
},
{
MethodName: "Action",
Handler: _Post_Action_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "post.proto",
}

View File

@@ -0,0 +1,69 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.8
// protoc (unknown)
// source: setting.proto
package feed
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
var File_setting_proto protoreflect.FileDescriptor
const file_setting_proto_rawDesc = "" +
"\n" +
"\x19social/feed/setting.proto\x12\x04feed\x1a\x11feed/blocks.proto2S\n" +
"\aSetting\x12\"\n" +
"\x04Info\x12\v.feed.Empty\x1a\v.feed.Empty\"\x00\x12$\n" +
"\x06Rights\x12\v.feed.Empty\x1a\v.feed.Empty\"\x00B\bZ\x06.;feedb\x06proto3"
var file_setting_proto_goTypes = []any{
(*Empty)(nil), // 0: feed.Empty
}
var file_setting_proto_depIdxs = []int32{
0, // 0: feed.Setting.Info:input_type -> feed.Empty
0, // 1: feed.Setting.Rights:input_type -> feed.Empty
0, // 2: feed.Setting.Info:output_type -> feed.Empty
0, // 3: feed.Setting.Rights:output_type -> feed.Empty
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_setting_proto_init() }
func file_setting_proto_init() {
if File_setting_proto != nil {
return
}
file_blocks_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_setting_proto_rawDesc), len(file_setting_proto_rawDesc)),
NumEnums: 0,
NumMessages: 0,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_setting_proto_goTypes,
DependencyIndexes: file_setting_proto_depIdxs,
}.Build()
File_setting_proto = out.File
file_setting_proto_goTypes = nil
file_setting_proto_depIdxs = nil
}

View File

@@ -0,0 +1,223 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: setting.proto
/*
Package feed is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package feed
import (
"context"
"errors"
"io"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
// Suppress "imported and not used" errors
var (
_ codes.Code
_ io.Reader
_ status.Status
_ = errors.New
_ = runtime.String
_ = utilities.NewDoubleArray
_ = metadata.Join
)
func request_Setting_Info_0(ctx context.Context, marshaler runtime.Marshaler, client SettingClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq Empty
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Info(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Setting_Info_0(ctx context.Context, marshaler runtime.Marshaler, server SettingServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq Empty
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Info(ctx, &protoReq)
return msg, metadata, err
}
func request_Setting_Rights_0(ctx context.Context, marshaler runtime.Marshaler, client SettingClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq Empty
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Rights(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Setting_Rights_0(ctx context.Context, marshaler runtime.Marshaler, server SettingServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq Empty
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Rights(ctx, &protoReq)
return msg, metadata, err
}
// RegisterSettingHandlerServer registers the http handlers for service Setting to "mux".
// UnaryRPC :call SettingServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterSettingHandlerFromEndpoint instead.
// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
func RegisterSettingHandlerServer(ctx context.Context, mux *runtime.ServeMux, server SettingServer) error {
mux.Handle(http.MethodPost, pattern_Setting_Info_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Setting/Info", runtime.WithHTTPPathPattern("/feed.Setting/Info"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Setting_Info_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Setting_Info_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Setting_Rights_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Setting/Rights", runtime.WithHTTPPathPattern("/feed.Setting/Rights"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Setting_Rights_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Setting_Rights_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterSettingHandlerFromEndpoint is same as RegisterSettingHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterSettingHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.NewClient(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterSettingHandler(ctx, mux, conn)
}
// RegisterSettingHandler registers the http handlers for service Setting to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterSettingHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterSettingHandlerClient(ctx, mux, NewSettingClient(conn))
}
// RegisterSettingHandlerClient registers the http handlers for service Setting
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "SettingClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "SettingClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "SettingClient" to call the correct interceptors. This client ignores the HTTP middlewares.
func RegisterSettingHandlerClient(ctx context.Context, mux *runtime.ServeMux, client SettingClient) error {
mux.Handle(http.MethodPost, pattern_Setting_Info_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Setting/Info", runtime.WithHTTPPathPattern("/feed.Setting/Info"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Setting_Info_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Setting_Info_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Setting_Rights_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Setting/Rights", runtime.WithHTTPPathPattern("/feed.Setting/Rights"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Setting_Rights_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Setting_Rights_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Setting_Info_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Setting", "Info"}, ""))
pattern_Setting_Rights_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Setting", "Rights"}, ""))
)
var (
forward_Setting_Info_0 = runtime.ForwardResponseMessage
forward_Setting_Rights_0 = runtime.ForwardResponseMessage
)

View File

@@ -0,0 +1,163 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc (unknown)
// source: setting.proto
package feed
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Setting_Info_FullMethodName = "/feed.Setting/Info"
Setting_Rights_FullMethodName = "/feed.Setting/Rights"
)
// SettingClient is the client API for Setting service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type SettingClient interface {
// 修改个人信息
Info(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
// 修改权限信息
Rights(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
}
type settingClient struct {
cc grpc.ClientConnInterface
}
func NewSettingClient(cc grpc.ClientConnInterface) SettingClient {
return &settingClient{cc}
}
func (c *settingClient) Info(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Empty)
err := c.cc.Invoke(ctx, Setting_Info_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *settingClient) Rights(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Empty)
err := c.cc.Invoke(ctx, Setting_Rights_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// SettingServer is the server API for Setting service.
// All implementations must embed UnimplementedSettingServer
// for forward compatibility.
type SettingServer interface {
// 修改个人信息
Info(context.Context, *Empty) (*Empty, error)
// 修改权限信息
Rights(context.Context, *Empty) (*Empty, error)
mustEmbedUnimplementedSettingServer()
}
// UnimplementedSettingServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedSettingServer struct{}
func (UnimplementedSettingServer) Info(context.Context, *Empty) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Info not implemented")
}
func (UnimplementedSettingServer) Rights(context.Context, *Empty) (*Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Rights not implemented")
}
func (UnimplementedSettingServer) mustEmbedUnimplementedSettingServer() {}
func (UnimplementedSettingServer) testEmbeddedByValue() {}
// UnsafeSettingServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to SettingServer will
// result in compilation errors.
type UnsafeSettingServer interface {
mustEmbedUnimplementedSettingServer()
}
func RegisterSettingServer(s grpc.ServiceRegistrar, srv SettingServer) {
// If the following call pancis, it indicates UnimplementedSettingServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Setting_ServiceDesc, srv)
}
func _Setting_Info_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SettingServer).Info(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Setting_Info_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SettingServer).Info(ctx, req.(*Empty))
}
return interceptor(ctx, in, info, handler)
}
func _Setting_Rights_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(Empty)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SettingServer).Rights(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Setting_Rights_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SettingServer).Rights(ctx, req.(*Empty))
}
return interceptor(ctx, in, info, handler)
}
// Setting_ServiceDesc is the grpc.ServiceDesc for Setting service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Setting_ServiceDesc = grpc.ServiceDesc{
ServiceName: "feed.Setting",
HandlerType: (*SettingServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Info",
Handler: _Setting_Info_Handler,
},
{
MethodName: "Rights",
Handler: _Setting_Rights_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "setting.proto",
}

View File

@@ -0,0 +1,194 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.8
// protoc (unknown)
// source: tag.proto
package feed
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type AddTagRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Tags []string `protobuf:"bytes,1,rep,name=tags,proto3" json:"tags,omitempty"` // 标签名称
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *AddTagRequest) Reset() {
*x = AddTagRequest{}
mi := &file_tag_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *AddTagRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AddTagRequest) ProtoMessage() {}
func (x *AddTagRequest) ProtoReflect() protoreflect.Message {
mi := &file_tag_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AddTagRequest.ProtoReflect.Descriptor instead.
func (*AddTagRequest) Descriptor() ([]byte, []int) {
return file_tag_proto_rawDescGZIP(), []int{0}
}
func (x *AddTagRequest) GetTags() []string {
if x != nil {
return x.Tags
}
return nil
}
type TagListReply struct {
state protoimpl.MessageState `protogen:"open.v1"`
Tags []*TagItem `protobuf:"bytes,1,rep,name=tags,proto3" json:"tags,omitempty"`
Total int64 `protobuf:"varint,2,opt,name=total,proto3" json:"total,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *TagListReply) Reset() {
*x = TagListReply{}
mi := &file_tag_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *TagListReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*TagListReply) ProtoMessage() {}
func (x *TagListReply) ProtoReflect() protoreflect.Message {
mi := &file_tag_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use TagListReply.ProtoReflect.Descriptor instead.
func (*TagListReply) Descriptor() ([]byte, []int) {
return file_tag_proto_rawDescGZIP(), []int{1}
}
func (x *TagListReply) GetTags() []*TagItem {
if x != nil {
return x.Tags
}
return nil
}
func (x *TagListReply) GetTotal() int64 {
if x != nil {
return x.Total
}
return 0
}
var File_tag_proto protoreflect.FileDescriptor
const file_tag_proto_rawDesc = "" +
"\n" +
"\x15social/feed/tag.proto\x12\x04feed\x1a\x11feed/blocks.proto\"#\n" +
"\rAddTagRequest\x12\x12\n" +
"\x04tags\x18\x01 \x03(\tR\x04tags\"G\n" +
"\fTagListReply\x12!\n" +
"\x04tags\x18\x01 \x03(\v2\r.feed.TagItemR\x04tags\x12\x14\n" +
"\x05total\x18\x02 \x01(\x03R\x05total2\xa2\x01\n" +
"\x03Tag\x120\n" +
"\x04List\x12\x12.feed.FetchRequest\x1a\x12.feed.TagListReply\"\x00\x122\n" +
"\x06Create\x12\x13.feed.AddTagRequest\x1a\x11.feed.StatusReply\"\x00\x125\n" +
"\bPostList\x12\x12.feed.FetchRequest\x1a\x13.feed.PostListReply\"\x00B\bZ\x06.;feedb\x06proto3"
var (
file_tag_proto_rawDescOnce sync.Once
file_tag_proto_rawDescData []byte
)
func file_tag_proto_rawDescGZIP() []byte {
file_tag_proto_rawDescOnce.Do(func() {
file_tag_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_tag_proto_rawDesc), len(file_tag_proto_rawDesc)))
})
return file_tag_proto_rawDescData
}
var file_tag_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_tag_proto_goTypes = []any{
(*AddTagRequest)(nil), // 0: feed.AddTagRequest
(*TagListReply)(nil), // 1: feed.TagListReply
(*TagItem)(nil), // 2: feed.TagItem
(*FetchRequest)(nil), // 3: feed.FetchRequest
(*StatusReply)(nil), // 4: feed.StatusReply
(*PostListReply)(nil), // 5: feed.PostListReply
}
var file_tag_proto_depIdxs = []int32{
2, // 0: feed.TagListReply.tags:type_name -> feed.TagItem
3, // 1: feed.Tag.List:input_type -> feed.FetchRequest
0, // 2: feed.Tag.Create:input_type -> feed.AddTagRequest
3, // 3: feed.Tag.PostList:input_type -> feed.FetchRequest
1, // 4: feed.Tag.List:output_type -> feed.TagListReply
4, // 5: feed.Tag.Create:output_type -> feed.StatusReply
5, // 6: feed.Tag.PostList:output_type -> feed.PostListReply
4, // [4:7] is the sub-list for method output_type
1, // [1:4] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_tag_proto_init() }
func file_tag_proto_init() {
if File_tag_proto != nil {
return
}
file_blocks_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_tag_proto_rawDesc), len(file_tag_proto_rawDesc)),
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_tag_proto_goTypes,
DependencyIndexes: file_tag_proto_depIdxs,
MessageInfos: file_tag_proto_msgTypes,
}.Build()
File_tag_proto = out.File
file_tag_proto_goTypes = nil
file_tag_proto_depIdxs = nil
}

View File

@@ -0,0 +1,289 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: tag.proto
/*
Package feed is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package feed
import (
"context"
"errors"
"io"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
// Suppress "imported and not used" errors
var (
_ codes.Code
_ io.Reader
_ status.Status
_ = errors.New
_ = runtime.String
_ = utilities.NewDoubleArray
_ = metadata.Join
)
func request_Tag_List_0(ctx context.Context, marshaler runtime.Marshaler, client TagClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.List(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Tag_List_0(ctx context.Context, marshaler runtime.Marshaler, server TagServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.List(ctx, &protoReq)
return msg, metadata, err
}
func request_Tag_Create_0(ctx context.Context, marshaler runtime.Marshaler, client TagClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq AddTagRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Create(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Tag_Create_0(ctx context.Context, marshaler runtime.Marshaler, server TagServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq AddTagRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Create(ctx, &protoReq)
return msg, metadata, err
}
func request_Tag_PostList_0(ctx context.Context, marshaler runtime.Marshaler, client TagClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.PostList(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Tag_PostList_0(ctx context.Context, marshaler runtime.Marshaler, server TagServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.PostList(ctx, &protoReq)
return msg, metadata, err
}
// RegisterTagHandlerServer registers the http handlers for service Tag to "mux".
// UnaryRPC :call TagServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterTagHandlerFromEndpoint instead.
// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
func RegisterTagHandlerServer(ctx context.Context, mux *runtime.ServeMux, server TagServer) error {
mux.Handle(http.MethodPost, pattern_Tag_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Tag/List", runtime.WithHTTPPathPattern("/feed.Tag/List"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Tag_List_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Tag_List_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Tag_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Tag/Create", runtime.WithHTTPPathPattern("/feed.Tag/Create"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Tag_Create_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Tag_Create_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Tag_PostList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Tag/PostList", runtime.WithHTTPPathPattern("/feed.Tag/PostList"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Tag_PostList_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Tag_PostList_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterTagHandlerFromEndpoint is same as RegisterTagHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterTagHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.NewClient(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterTagHandler(ctx, mux, conn)
}
// RegisterTagHandler registers the http handlers for service Tag to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterTagHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterTagHandlerClient(ctx, mux, NewTagClient(conn))
}
// RegisterTagHandlerClient registers the http handlers for service Tag
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "TagClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "TagClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "TagClient" to call the correct interceptors. This client ignores the HTTP middlewares.
func RegisterTagHandlerClient(ctx context.Context, mux *runtime.ServeMux, client TagClient) error {
mux.Handle(http.MethodPost, pattern_Tag_List_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Tag/List", runtime.WithHTTPPathPattern("/feed.Tag/List"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Tag_List_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Tag_List_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Tag_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Tag/Create", runtime.WithHTTPPathPattern("/feed.Tag/Create"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Tag_Create_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Tag_Create_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Tag_PostList_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Tag/PostList", runtime.WithHTTPPathPattern("/feed.Tag/PostList"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Tag_PostList_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Tag_PostList_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Tag_List_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Tag", "List"}, ""))
pattern_Tag_Create_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Tag", "Create"}, ""))
pattern_Tag_PostList_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Tag", "PostList"}, ""))
)
var (
forward_Tag_List_0 = runtime.ForwardResponseMessage
forward_Tag_Create_0 = runtime.ForwardResponseMessage
forward_Tag_PostList_0 = runtime.ForwardResponseMessage
)

View File

@@ -0,0 +1,203 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc (unknown)
// source: tag.proto
package feed
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Tag_List_FullMethodName = "/feed.Tag/List"
Tag_Create_FullMethodName = "/feed.Tag/Create"
Tag_PostList_FullMethodName = "/feed.Tag/PostList"
)
// TagClient is the client API for Tag service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type TagClient interface {
// 标签列表
List(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*TagListReply, error)
// 新建标签
Create(ctx context.Context, in *AddTagRequest, opts ...grpc.CallOption) (*StatusReply, error)
// 话题相关的文章
PostList(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error)
}
type tagClient struct {
cc grpc.ClientConnInterface
}
func NewTagClient(cc grpc.ClientConnInterface) TagClient {
return &tagClient{cc}
}
func (c *tagClient) List(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*TagListReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(TagListReply)
err := c.cc.Invoke(ctx, Tag_List_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *tagClient) Create(ctx context.Context, in *AddTagRequest, opts ...grpc.CallOption) (*StatusReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(StatusReply)
err := c.cc.Invoke(ctx, Tag_Create_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *tagClient) PostList(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(PostListReply)
err := c.cc.Invoke(ctx, Tag_PostList_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// TagServer is the server API for Tag service.
// All implementations must embed UnimplementedTagServer
// for forward compatibility.
type TagServer interface {
// 标签列表
List(context.Context, *FetchRequest) (*TagListReply, error)
// 新建标签
Create(context.Context, *AddTagRequest) (*StatusReply, error)
// 话题相关的文章
PostList(context.Context, *FetchRequest) (*PostListReply, error)
mustEmbedUnimplementedTagServer()
}
// UnimplementedTagServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedTagServer struct{}
func (UnimplementedTagServer) List(context.Context, *FetchRequest) (*TagListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method List not implemented")
}
func (UnimplementedTagServer) Create(context.Context, *AddTagRequest) (*StatusReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Create not implemented")
}
func (UnimplementedTagServer) PostList(context.Context, *FetchRequest) (*PostListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method PostList not implemented")
}
func (UnimplementedTagServer) mustEmbedUnimplementedTagServer() {}
func (UnimplementedTagServer) testEmbeddedByValue() {}
// UnsafeTagServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to TagServer will
// result in compilation errors.
type UnsafeTagServer interface {
mustEmbedUnimplementedTagServer()
}
func RegisterTagServer(s grpc.ServiceRegistrar, srv TagServer) {
// If the following call pancis, it indicates UnimplementedTagServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Tag_ServiceDesc, srv)
}
func _Tag_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FetchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TagServer).List(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Tag_List_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TagServer).List(ctx, req.(*FetchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Tag_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AddTagRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TagServer).Create(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Tag_Create_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TagServer).Create(ctx, req.(*AddTagRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Tag_PostList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FetchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TagServer).PostList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Tag_PostList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TagServer).PostList(ctx, req.(*FetchRequest))
}
return interceptor(ctx, in, info, handler)
}
// Tag_ServiceDesc is the grpc.ServiceDesc for Tag service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Tag_ServiceDesc = grpc.ServiceDesc{
ServiceName: "feed.Tag",
HandlerType: (*TagServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "List",
Handler: _Tag_List_Handler,
},
{
MethodName: "Create",
Handler: _Tag_Create_Handler,
},
{
MethodName: "PostList",
Handler: _Tag_PostList_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "tag.proto",
}

View File

@@ -0,0 +1,76 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.8
// protoc (unknown)
// source: timeline.proto
package feed
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
var File_timeline_proto protoreflect.FileDescriptor
const file_timeline_proto_rawDesc = "" +
"\n" +
"\x1asocial/feed/timeline.proto\x12\x04feed\x1a\x11feed/blocks.proto2\xde\x01\n" +
"\bTimeline\x126\n" +
"\tRecommend\x12\x12.feed.FetchRequest\x1a\x13.feed.PostListReply\"\x00\x123\n" +
"\x06Friend\x12\x12.feed.FetchRequest\x1a\x13.feed.PostListReply\"\x00\x123\n" +
"\x06Follow\x12\x12.feed.FetchRequest\x1a\x13.feed.PostListReply\"\x00\x120\n" +
"\x03Hot\x12\x12.feed.FetchRequest\x1a\x13.feed.PostListReply\"\x00B\bZ\x06.;feedb\x06proto3"
var file_timeline_proto_goTypes = []any{
(*FetchRequest)(nil), // 0: feed.FetchRequest
(*PostListReply)(nil), // 1: feed.PostListReply
}
var file_timeline_proto_depIdxs = []int32{
0, // 0: feed.Timeline.Recommend:input_type -> feed.FetchRequest
0, // 1: feed.Timeline.Friend:input_type -> feed.FetchRequest
0, // 2: feed.Timeline.Follow:input_type -> feed.FetchRequest
0, // 3: feed.Timeline.Hot:input_type -> feed.FetchRequest
1, // 4: feed.Timeline.Recommend:output_type -> feed.PostListReply
1, // 5: feed.Timeline.Friend:output_type -> feed.PostListReply
1, // 6: feed.Timeline.Follow:output_type -> feed.PostListReply
1, // 7: feed.Timeline.Hot:output_type -> feed.PostListReply
4, // [4:8] is the sub-list for method output_type
0, // [0:4] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_timeline_proto_init() }
func file_timeline_proto_init() {
if File_timeline_proto != nil {
return
}
file_blocks_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_timeline_proto_rawDesc), len(file_timeline_proto_rawDesc)),
NumEnums: 0,
NumMessages: 0,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_timeline_proto_goTypes,
DependencyIndexes: file_timeline_proto_depIdxs,
}.Build()
File_timeline_proto = out.File
file_timeline_proto_goTypes = nil
file_timeline_proto_depIdxs = nil
}

View File

@@ -0,0 +1,355 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: timeline.proto
/*
Package feed is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package feed
import (
"context"
"errors"
"io"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
// Suppress "imported and not used" errors
var (
_ codes.Code
_ io.Reader
_ status.Status
_ = errors.New
_ = runtime.String
_ = utilities.NewDoubleArray
_ = metadata.Join
)
func request_Timeline_Recommend_0(ctx context.Context, marshaler runtime.Marshaler, client TimelineClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Recommend(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Timeline_Recommend_0(ctx context.Context, marshaler runtime.Marshaler, server TimelineServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Recommend(ctx, &protoReq)
return msg, metadata, err
}
func request_Timeline_Friend_0(ctx context.Context, marshaler runtime.Marshaler, client TimelineClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Friend(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Timeline_Friend_0(ctx context.Context, marshaler runtime.Marshaler, server TimelineServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Friend(ctx, &protoReq)
return msg, metadata, err
}
func request_Timeline_Follow_0(ctx context.Context, marshaler runtime.Marshaler, client TimelineClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Follow(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Timeline_Follow_0(ctx context.Context, marshaler runtime.Marshaler, server TimelineServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Follow(ctx, &protoReq)
return msg, metadata, err
}
func request_Timeline_Hot_0(ctx context.Context, marshaler runtime.Marshaler, client TimelineClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
msg, err := client.Hot(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Timeline_Hot_0(ctx context.Context, marshaler runtime.Marshaler, server TimelineServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq FetchRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Hot(ctx, &protoReq)
return msg, metadata, err
}
// RegisterTimelineHandlerServer registers the http handlers for service Timeline to "mux".
// UnaryRPC :call TimelineServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterTimelineHandlerFromEndpoint instead.
// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
func RegisterTimelineHandlerServer(ctx context.Context, mux *runtime.ServeMux, server TimelineServer) error {
mux.Handle(http.MethodPost, pattern_Timeline_Recommend_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Timeline/Recommend", runtime.WithHTTPPathPattern("/feed.Timeline/Recommend"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Timeline_Recommend_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Timeline_Recommend_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Timeline_Friend_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Timeline/Friend", runtime.WithHTTPPathPattern("/feed.Timeline/Friend"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Timeline_Friend_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Timeline_Friend_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Timeline_Follow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Timeline/Follow", runtime.WithHTTPPathPattern("/feed.Timeline/Follow"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Timeline_Follow_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Timeline_Follow_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Timeline_Hot_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/feed.Timeline/Hot", runtime.WithHTTPPathPattern("/feed.Timeline/Hot"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Timeline_Hot_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Timeline_Hot_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterTimelineHandlerFromEndpoint is same as RegisterTimelineHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterTimelineHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.NewClient(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterTimelineHandler(ctx, mux, conn)
}
// RegisterTimelineHandler registers the http handlers for service Timeline to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterTimelineHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterTimelineHandlerClient(ctx, mux, NewTimelineClient(conn))
}
// RegisterTimelineHandlerClient registers the http handlers for service Timeline
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "TimelineClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "TimelineClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "TimelineClient" to call the correct interceptors. This client ignores the HTTP middlewares.
func RegisterTimelineHandlerClient(ctx context.Context, mux *runtime.ServeMux, client TimelineClient) error {
mux.Handle(http.MethodPost, pattern_Timeline_Recommend_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Timeline/Recommend", runtime.WithHTTPPathPattern("/feed.Timeline/Recommend"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Timeline_Recommend_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Timeline_Recommend_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Timeline_Friend_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Timeline/Friend", runtime.WithHTTPPathPattern("/feed.Timeline/Friend"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Timeline_Friend_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Timeline_Friend_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Timeline_Follow_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Timeline/Follow", runtime.WithHTTPPathPattern("/feed.Timeline/Follow"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Timeline_Follow_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Timeline_Follow_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Timeline_Hot_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/feed.Timeline/Hot", runtime.WithHTTPPathPattern("/feed.Timeline/Hot"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Timeline_Hot_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Timeline_Hot_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Timeline_Recommend_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Timeline", "Recommend"}, ""))
pattern_Timeline_Friend_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Timeline", "Friend"}, ""))
pattern_Timeline_Follow_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Timeline", "Follow"}, ""))
pattern_Timeline_Hot_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"feed.Timeline", "Hot"}, ""))
)
var (
forward_Timeline_Recommend_0 = runtime.ForwardResponseMessage
forward_Timeline_Friend_0 = runtime.ForwardResponseMessage
forward_Timeline_Follow_0 = runtime.ForwardResponseMessage
forward_Timeline_Hot_0 = runtime.ForwardResponseMessage
)

View File

@@ -0,0 +1,247 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc (unknown)
// source: timeline.proto
package feed
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Timeline_Recommend_FullMethodName = "/feed.Timeline/Recommend"
Timeline_Friend_FullMethodName = "/feed.Timeline/Friend"
Timeline_Follow_FullMethodName = "/feed.Timeline/Follow"
Timeline_Hot_FullMethodName = "/feed.Timeline/Hot"
)
// TimelineClient is the client API for Timeline service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
//
// 实时动态
type TimelineClient interface {
// 推荐
Recommend(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error)
// 好友动态
Friend(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error)
// 关注的动态
Follow(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error)
// 热门
Hot(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error)
}
type timelineClient struct {
cc grpc.ClientConnInterface
}
func NewTimelineClient(cc grpc.ClientConnInterface) TimelineClient {
return &timelineClient{cc}
}
func (c *timelineClient) Recommend(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(PostListReply)
err := c.cc.Invoke(ctx, Timeline_Recommend_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *timelineClient) Friend(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(PostListReply)
err := c.cc.Invoke(ctx, Timeline_Friend_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *timelineClient) Follow(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(PostListReply)
err := c.cc.Invoke(ctx, Timeline_Follow_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *timelineClient) Hot(ctx context.Context, in *FetchRequest, opts ...grpc.CallOption) (*PostListReply, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(PostListReply)
err := c.cc.Invoke(ctx, Timeline_Hot_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// TimelineServer is the server API for Timeline service.
// All implementations must embed UnimplementedTimelineServer
// for forward compatibility.
//
// 实时动态
type TimelineServer interface {
// 推荐
Recommend(context.Context, *FetchRequest) (*PostListReply, error)
// 好友动态
Friend(context.Context, *FetchRequest) (*PostListReply, error)
// 关注的动态
Follow(context.Context, *FetchRequest) (*PostListReply, error)
// 热门
Hot(context.Context, *FetchRequest) (*PostListReply, error)
mustEmbedUnimplementedTimelineServer()
}
// UnimplementedTimelineServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedTimelineServer struct{}
func (UnimplementedTimelineServer) Recommend(context.Context, *FetchRequest) (*PostListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Recommend not implemented")
}
func (UnimplementedTimelineServer) Friend(context.Context, *FetchRequest) (*PostListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Friend not implemented")
}
func (UnimplementedTimelineServer) Follow(context.Context, *FetchRequest) (*PostListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Follow not implemented")
}
func (UnimplementedTimelineServer) Hot(context.Context, *FetchRequest) (*PostListReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method Hot not implemented")
}
func (UnimplementedTimelineServer) mustEmbedUnimplementedTimelineServer() {}
func (UnimplementedTimelineServer) testEmbeddedByValue() {}
// UnsafeTimelineServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to TimelineServer will
// result in compilation errors.
type UnsafeTimelineServer interface {
mustEmbedUnimplementedTimelineServer()
}
func RegisterTimelineServer(s grpc.ServiceRegistrar, srv TimelineServer) {
// If the following call pancis, it indicates UnimplementedTimelineServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Timeline_ServiceDesc, srv)
}
func _Timeline_Recommend_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FetchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TimelineServer).Recommend(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Timeline_Recommend_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TimelineServer).Recommend(ctx, req.(*FetchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Timeline_Friend_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FetchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TimelineServer).Friend(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Timeline_Friend_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TimelineServer).Friend(ctx, req.(*FetchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Timeline_Follow_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FetchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TimelineServer).Follow(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Timeline_Follow_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TimelineServer).Follow(ctx, req.(*FetchRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Timeline_Hot_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(FetchRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TimelineServer).Hot(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Timeline_Hot_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TimelineServer).Hot(ctx, req.(*FetchRequest))
}
return interceptor(ctx, in, info, handler)
}
// Timeline_ServiceDesc is the grpc.ServiceDesc for Timeline service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Timeline_ServiceDesc = grpc.ServiceDesc{
ServiceName: "feed.Timeline",
HandlerType: (*TimelineServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Recommend",
Handler: _Timeline_Recommend_Handler,
},
{
MethodName: "Friend",
Handler: _Timeline_Friend_Handler,
},
{
MethodName: "Follow",
Handler: _Timeline_Follow_Handler,
},
{
MethodName: "Hot",
Handler: _Timeline_Hot_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "timeline.proto",
}

View File

@@ -0,0 +1,66 @@
syntax = "proto3";
package feed;
option go_package = ".;feed";
message FetchRequest {
int64 page_no=1; // 页数
int64 page_size=2; // 每页记录数
map<string,string> params=3; // 条件参数,key=val,eg key:category_id=?,vlaue=11
}
message IdentRequest{
int64 id = 1; // 唯一ID
string identity = 2; // 唯一码
}
message VersionRequest {
int64 version=1; // 时序版本号
}
message SearchRequest {
string keyword=1; //关键词
}
message StatusReply{
string data=1; // 数据
int64 timeseq=2; // 响应时间序列
}
message Empty{
}
// 推文列表
message PostListReply{
repeated PostItem list = 1;
int64 cnt = 2;
}
// 推文
message PostItem{
string identity = 1; // 唯一标识
string content = 2; // 内容
int64 feed_id=3; // 通行证ID
string feed_identity = 4; // 通行证Identity
bool is_open =5; // 是否公开默认为0-公开1-不公开
int64 cnt_unlike = 6; // 点踩数量
int64 cnt_comment = 7; // 评论数量
int64 cnt_like = 8; // 点赞数量
repeated AttachItem attachs = 9; // 附件信息
repeated TagItem tags = 10; // 所属话题
}
// 附件
message AttachItem{
string identity = 1; // 唯一标识
string attach_type = 2; // 文件类型
string url = 3; // 文件路径
}
// 标签
message TagItem {
string key = 1; // 标签唯一码
string content = 2; // 标签内容
}

View File

@@ -0,0 +1,53 @@
syntax = "proto3";
package feed;
option go_package =".;feed";
import "blocks.proto";
// 推文相关操作
service Post{
// 推文列表
rpc Fetch(FetchRequest) returns (PostListReply){};
// 新建推文
rpc Create (PostItem) returns (StatusReply){};
// 修改推文
rpc Change (PostItem) returns (StatusReply){};
// 删除推文
rpc Remove (IdentRequest) returns (StatusReply){};
// 评论列表
rpc CommentList (FetchRequest) returns (CommentListReply){};
// 新建评论
rpc AddComment (CommentItem) returns (StatusReply){};
// 删除评论
rpc DeleteComment (IdentRequest) returns (StatusReply){};
// 计数操作
rpc Action (PostActionRequest) returns (StatusReply){};
}
// 推文评论列表
message CommentListReply{
repeated CommentItem list = 1; // 评论列表
int64 total = 2;
}
message CommentItem{
string identity = 1; // 评论identity
string post_identity = 2; // 被评论唯一标识
string feed_identity=3; // 评论人唯一标识
string content = 4; // 评论内容
repeated CommentItem sub_comment =5; // 子评论
}
message PostActionRequest{
string action_op=1; //操作运作ilike,unlike
string action_type=2; //类别:推文,评论
string identity = 3; // 唯一标识
}

View File

@@ -0,0 +1,12 @@
syntax = "proto3";
package feed;
option go_package =".;feed";
import "blocks.proto";
service Setting{
// 修改个人信息
rpc Info (Empty) returns (Empty){};
// 修改权限信息
rpc Rights (Empty) returns (Empty){};
}

View File

@@ -0,0 +1,21 @@
syntax = "proto3";
package feed;
option go_package =".;feed";
import "blocks.proto";
service Tag{
// 标签列表
rpc List (FetchRequest) returns (TagListReply){};
// 新建标签
rpc Create (AddTagRequest) returns (StatusReply){};
// 话题相关的文章
rpc PostList (FetchRequest) returns (PostListReply){};
}
message AddTagRequest {
repeated string tags = 1; // 标签名称
}
message TagListReply{
repeated TagItem tags = 1;
int64 total = 2;
}

View File

@@ -0,0 +1,21 @@
syntax = "proto3";
package feed;
option go_package =".;feed";
import "blocks.proto";
// 实时动态
service Timeline{
// 推荐
rpc Recommend (FetchRequest) returns (PostListReply){};
// 好友动态
rpc Friend (FetchRequest) returns (PostListReply){};
// 关注的动态
rpc Follow (FetchRequest) returns (PostListReply){};
// 热门
rpc Hot (FetchRequest) returns (PostListReply){};
}

View File

@@ -0,0 +1,32 @@
filebeat.inputs:
- type: log
enabled: true
# 开启json解析
json.keys_under_root: true
json.add_error_key: true
# 日志文件路径
paths:
- ./logs/content/error.log
- ./logs/content/slow.log
setup.template.settings:
index.number_of_shards: 1
# 定义kafka topic field
fields:
log_topic: scf.pb.dev
# 输出到kafka
output.kafka:
hosts: ["127.0.0.1:9092"]
topic: '%{[fields.log_topic]}'
partition.round_robin:
reachable_only: false
required_acks: 1
keep_alive: 10s
# ================================= Processors =================================
processors:
- decode_json_fields:
fields: ['@timestamp','level','content','trace','span','duration']
target: ""

View File

@@ -0,0 +1,5 @@
#install
go install github.com/securego/gosec/v2/cmd/gosec@latest
#run
gosec -fmt=json -out=./test/lint/gosec.json ./...

View File

@@ -0,0 +1,14 @@
# 由于goctl 不能编译多个proto文件所以先要安装合并工具
# go install git.apinb.com/bsm-tools/proto-merge@v0.0.3
# 1. 先合并
proto-merge ./proto/*.proto ./proto/feeds.proto
# 2. goctl 生成代码至/gen
goctl rpc protoc ./proto/feeds.proto --go_out=./external/pb --go-grpc_out=./external/pb --zrpc_out=./ -m --style go_zero
# 3. 清理无用文件
rm ./proto/feeds.proto
mv ./client ./external/
rm feeds.go
rm ./etc/feeds.yaml

View File

@@ -0,0 +1,245 @@
{
"swagger": "2.0",
"info": {
"title": "blocks.proto",
"version": "version not set"
},
"tags": [
{
"name": "Post"
},
{
"name": "Setting"
},
{
"name": "Tag"
},
{
"name": "Timeline"
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {},
"definitions": {
"feedAttachItem": {
"type": "object",
"properties": {
"identity": {
"type": "string",
"title": "唯一标识"
},
"attachType": {
"type": "string",
"title": "文件类型"
},
"url": {
"type": "string",
"title": "文件路径"
}
},
"title": "附件"
},
"feedCommentItem": {
"type": "object",
"properties": {
"identity": {
"type": "string",
"title": "评论identity"
},
"postIdentity": {
"type": "string",
"title": "被评论唯一标识"
},
"feedIdentity": {
"type": "string",
"title": "评论人唯一标识"
},
"content": {
"type": "string",
"title": "评论内容"
},
"subComment": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/feedCommentItem"
},
"title": "子评论"
}
}
},
"feedCommentListReply": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/feedCommentItem"
},
"title": "评论列表"
},
"total": {
"type": "string",
"format": "int64"
}
},
"title": "推文评论列表"
},
"feedEmpty": {
"type": "object"
},
"feedPostItem": {
"type": "object",
"properties": {
"identity": {
"type": "string",
"title": "唯一标识"
},
"content": {
"type": "string",
"title": "内容"
},
"feedId": {
"type": "string",
"format": "int64",
"title": "通行证ID"
},
"feedIdentity": {
"type": "string",
"title": "通行证Identity"
},
"isOpen": {
"type": "boolean",
"title": "是否公开默认为0-公开1-不公开"
},
"cntUnlike": {
"type": "string",
"format": "int64",
"title": "点踩数量"
},
"cntComment": {
"type": "string",
"format": "int64",
"title": "评论数量"
},
"cntLike": {
"type": "string",
"format": "int64",
"title": "点赞数量"
},
"attachs": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/feedAttachItem"
},
"title": "附件信息"
},
"tags": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/feedTagItem"
},
"title": "所属话题"
}
},
"title": "推文"
},
"feedPostListReply": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/feedPostItem"
}
},
"cnt": {
"type": "string",
"format": "int64"
}
},
"title": "推文列表"
},
"feedStatusReply": {
"type": "object",
"properties": {
"data": {
"type": "string",
"title": "数据"
},
"timeseq": {
"type": "string",
"format": "int64",
"title": "响应时间序列"
}
}
},
"feedTagItem": {
"type": "object",
"properties": {
"key": {
"type": "string",
"title": "标签唯一码"
},
"content": {
"type": "string",
"title": "标签内容"
}
},
"title": "标签"
},
"feedTagListReply": {
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/feedTagItem"
}
},
"total": {
"type": "string",
"format": "int64"
}
}
},
"protobufAny": {
"type": "object",
"properties": {
"@type": {
"type": "string"
}
},
"additionalProperties": {}
},
"rpcStatus": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/protobufAny"
}
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
{
"Golang errors": {},
"Issues": [],
"Stats": {
"files": 24,
"lines": 2377,
"nosec": 0,
"found": 0
},
"GosecVersion": "dev"
}

View File

@@ -0,0 +1,2 @@
# group

View File

@@ -0,0 +1,49 @@
version: v2
plugins:
- local: protoc-gen-go
out: pb
opt:
- paths=source_relative
- local: protoc-gen-go
out: ../../bsm-sdk/client/golang/passport
opt:
- paths=source_relative
- local: protoc-gen-go-grpc
out: pb
opt:
- paths=source_relative
- local: protoc-gen-go-grpc
out: ../../bsm-sdk/client/golang/passport
opt:
- paths=source_relative
- local: protoc-gen-grpc-gateway
out: pb
opt:
- paths=source_relative
- generate_unbound_methods=True
- local: protoc-gen-slc
out: ./
- local: protoc-gen-ts
out: ../../bsm-sdk/client/typescript
- local: protoc-gen-dart
out: ../../bsm-sdk/client/dart/passport
opt:
- grpc
- local: protoc-gen-openapiv2
out: ./swagger
opt: allow_merge=true,merge_file_name=passport
- local: protoc-gen-openapiv2
out: ../../bsm-sdk/client/docs/passport
opt: allow_merge=true,merge_file_name=passport
- local: protoc-gen-markdown
out: ../../bsm-sdk/client/docs/passport

View File

@@ -0,0 +1,10 @@
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2
lint:
use:
- STANDARD
modules:
- path: proto
breaking:
use:
- FILE

View File

@@ -0,0 +1,4 @@
package main
func main() {
}

View File

@@ -0,0 +1,45 @@
/**
* @Author: david.yan(david.yan@qq.com)
* @Date: 2021-11-26 15:25:03
*/
package main
import (
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-social/group/internal/config"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
"git.apinb.com/bsm-social/group/internal/server"
)
var (
ServiceKey = "group"
)
func main() {
config.New(ServiceKey)
impl.NewImpl()
// 初始化服务
s := server.New(config.Spec.Addr)
srv := service.New(
s.Grpc,
&service.Options{
Addr: config.Spec.Addr,
MsConf: config.Spec.MicroService,
EtcdClient: impl.EtcdService,
GatewayCtx: s.Ctx,
GatewayConf: config.Spec.Gateway,
GatewayMux: s.Mux,
},
)
// 注册:初始化数据
srv.Use(models.InitData)
// 停止服务
defer srv.Stop()
// 启动服务
srv.Start()
}

View File

@@ -0,0 +1,39 @@
Service: group
Port: 12247
Databases:
Driver: postgres
Source:
- host=47.109.77.183 user=postgres password=CHANGE_ME dbname=bsm_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
Cache: redis://null:CHANGE_ME@47.109.77.183:6379/
# 微服务设置
MicroService:
Enable: false
Anonymous:
- passport.ping.hello
# Gateway 设置
Gateway:
Enable: true
Port: 12425
# 微服务调用密钥
SecretKey: 6ad9529688041483f458f8de11ed16ff
Token:
Prefix: "/token/"
Expire: 86400
# Rpc:
# fts:
# Endpoint: https://api-v2.traingo.cn/fts/v2
# SecretKey: 4ef05311358cd1c8f787281f08b38b1c
# 链路追踪,性能监控,日志收集
# APM:
# Platform: elasticAPM
# Endpoint: http://127.0.0.1:14268/api/traces

View File

@@ -0,0 +1,39 @@
Service: group
Port: 12247
Databases:
Driver: postgres
Source:
- host=47.109.77.183 user=postgres password=CHANGE_ME dbname=bsm_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
Cache: redis://null:CHANGE_ME@47.109.77.183:6379/
# 微服务设置
MicroService:
Enable: false
Anonymous:
- passport.ping.hello
# Gateway 设置
Gateway:
Enable: true
Port: 12425
# 微服务调用密钥
SecretKey: 6ad9529688041483f458f8de11ed16ff
Token:
Prefix: "/token/"
Expire: 86400
# Rpc:
# fts:
# Endpoint: https://api-v2.traingo.cn/fts/v2
# SecretKey: 4ef05311358cd1c8f787281f08b38b1c
# 链路追踪,性能监控,日志收集
# APM:
# Platform: elasticAPM
# Endpoint: http://127.0.0.1:14268/api/traces

View File

@@ -0,0 +1,39 @@
Service: group
Port: 12247
Databases:
Driver: postgres
Source:
- host=47.109.77.183 user=postgres password=CHANGE_ME dbname=bsm_dev port=5432 sslmode=disable TimeZone=Asia/Shanghai
# cache DB的选择请在后面直接带参数不带会自动HASH计算选择DB库。
Cache: redis://null:CHANGE_ME@47.109.77.183:6379/
# 微服务设置
MicroService:
Enable: false
Anonymous:
- passport.ping.hello
# Gateway 设置
Gateway:
Enable: true
Port: 12425
# 微服务调用密钥
SecretKey: 6ad9529688041483f458f8de11ed16ff
Token:
Prefix: "/token/"
Expire: 86400
# Rpc:
# fts:
# Endpoint: https://api-v2.traingo.cn/fts/v2
# SecretKey: 4ef05311358cd1c8f787281f08b38b1c
# 链路追踪,性能监控,日志收集
# APM:
# Platform: elasticAPM
# Endpoint: http://127.0.0.1:14268/api/traces

View File

@@ -0,0 +1,8 @@
[program:bsm-social-group]
command=/data/app/bsm-social-group
directory=/data/app
autostart=true
autorestart=true
user=root
redirect_stderr=true
stdout_logfile=/data/app/logs/social-group.log

50
apps/social/group/go.mod Normal file
View File

@@ -0,0 +1,50 @@
module git.apinb.com/bsm-social/group
go 1.26.5
require (
git.apinb.com/bsm-sdk/core v0.2.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0
github.com/patrickmn/go-cache v2.1.0+incompatible
go.etcd.io/etcd/client/v3 v3.6.12
google.golang.org/grpc v1.81.1
google.golang.org/protobuf v1.36.11
gorm.io/gorm v1.31.1
)
require (
filippo.io/edwards25519 v1.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.7.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-sql-driver/mysql v1.10.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.10.0 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/oklog/ulid/v2 v2.1.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/redis/go-redis/v9 v9.20.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
go.etcd.io/etcd/api/v3 v3.6.12 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.6.12 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.28.0 // indirect
golang.org/x/net v0.55.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.45.0 // indirect
golang.org/x/text v0.37.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.6.0 // indirect
gorm.io/driver/postgres v1.6.0 // indirect
)

161
apps/social/group/go.sum Normal file
View File

@@ -0,0 +1,161 @@
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
git.apinb.com/bsm-sdk/core v0.2.0 h1:/e9yqpsbKBrRgMiGpS3KX2O4qDLxo5V5GpPSLNGxEKw=
git.apinb.com/bsm-sdk/core v0.2.0/go.mod h1:E9T6Eboo/0Zb36BjkKbIgvFzq4fQ2Q8P/7y5zmYTI6Y=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/coreos/go-systemd/v22 v22.7.0 h1:LAEzFkke61DFROc7zNLX/WA2i5J8gYqe0rSj9KI28KA=
github.com/coreos/go-systemd/v22 v22.7.0/go.mod h1:xNUYtjHu2EDXbsxz1i41wouACIwT7Ybq9o0BQhMwD0w=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw=
github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY=
github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.10.0 h1:VhSvgU2jSli8o3AqIEOTJr7rZwAEUVo4E4XhR94Zfr0=
github.com/jackc/pgx/v5 v5.10.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.20.0 h1:WnQYxLkgO2xiXTCJY0ldIiI8dNqCDlQAG+AtaH7a2a0=
github.com/redis/go-redis/v9 v9.20.0/go.mod h1:v/M13XI1PVCDcm01VtPFOADfZtHf8YW3baQf57KlIkA=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
go.etcd.io/etcd/api/v3 v3.6.12 h1:OLOZUKEuAA36TR48F0cIaa8FdzrWygjyfrJxXg4iDgs=
go.etcd.io/etcd/api/v3 v3.6.12/go.mod h1:p14EIQXHbuOQbVvL/WEes5uqKnxP9AgKJgpjbMVvzvE=
go.etcd.io/etcd/client/pkg/v3 v3.6.12 h1:36zzB+pQOdHbhN+kH2iJz/K8bJn0ZLtLfPPO7jozTDo=
go.etcd.io/etcd/client/pkg/v3 v3.6.12/go.mod h1:hh2+ZXtfLzs3o6mn92ntgNPBrTJJOvXqICM5g3L3DMY=
go.etcd.io/etcd/client/v3 v3.6.12 h1:kMSP6JcPZMqSJiX+TXdUIBU/4eXEZWBAaui4VihMbIc=
go.etcd.io/etcd/client/v3 v3.6.12/go.mod h1:CMs6fJWYiZQk4ytFjd4lE1diOvvRMmtbbn/alZXd3dQ=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw=
go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A=
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa h1:Kjn0N0tCrDgiAFW+lGO4JZ3ck44CehvJQMAwj9QF0G8=
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:q4lMZS6kskjT5HvCPrnnypcDPVJqT/f4nfxmkE7gryY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ=
google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4=
gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo=
gorm.io/gorm v1.31.1 h1:7CA8FTFz/gRfgqgpeKIBcervUn3xSyPUmr6B2WXJ7kg=
gorm.io/gorm v1.31.1/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=

View File

@@ -0,0 +1,62 @@
package config
import (
"net"
"git.apinb.com/bsm-sdk/core/conf"
"git.apinb.com/bsm-sdk/core/crypto/encipher"
"git.apinb.com/bsm-sdk/core/env"
)
var (
Spec SrvConfig
)
type SrvConfig struct {
conf.Base `yaml:",inline"`
Databases *conf.DBConf `yaml:"Databases"`
MicroService *conf.MicroServiceConf `yaml:"MicroService"`
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
Gateway *conf.GatewayConf `yaml:"Gateway"`
Apm *conf.ApmConf `yaml:"APM"`
Etcd *conf.EtcdConf `yaml:"Etcd"`
WeChat *WeChatConf `yaml:"WeChatConf"`
Token *TokenConf `yaml:"Token"`
Kyc *KycConf `yaml:"Kyc"`
}
type KycConf struct {
Provider string `yaml:"Provider"`
BaseUrl string `yaml:"BaseUrl"`
ApiSecret string `yaml:"ApiSecret"`
ApiToken string `yaml:"ApiToken"`
ApiArgs string `yaml:"ApiArgs"`
}
type TokenConf struct {
Prefix string `yaml:"Prefix"`
Expire int `yaml:"Expire"`
}
type WeChatConf struct {
AppID string `json:"app_id"`
AppSecret string `json:"app_secret"`
}
func New(srvKey string) {
// 初始化配置 创建一个新的配置实例,用于服务配置
conf.New(srvKey, &Spec)
// 配置校验 服务IP,端口; 端口如果不合规,则随机分配端口
Spec.Port = conf.CheckPort(Spec.Port)
Spec.BindIP = conf.CheckIP(Spec.BindIP)
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
// 配置校验 服务名称地址及监听地址不能为空
conf.NotNil(Spec.Service, Spec.Cache)
// 初始化加密SecretKey
encipher.New(env.Runtime.JwtSecretKey)
conf.PrintInfo(Spec.Addr)
}

View File

@@ -0,0 +1,25 @@
package impl
import (
"git.apinb.com/bsm-sdk/core/cache/redis"
"git.apinb.com/bsm-sdk/core/with"
"git.apinb.com/bsm-social/group/internal/config"
cache "github.com/patrickmn/go-cache"
clientv3 "go.etcd.io/etcd/client/v3"
"gorm.io/gorm"
)
var (
RedisService *redis.RedisClient
EtcdService *clientv3.Client
DBService *gorm.DB
MemorySerice *cache.Cache
)
func NewImpl() {
// with activating
MemorySerice = with.Memory(nil)
RedisService = with.RedisCache(config.Spec.Cache) // redis cache
DBService = with.Databases(config.Spec.Databases, nil) // model
EtcdService = with.Etcd(config.Spec.Etcd) // etcd
}

View File

@@ -0,0 +1,15 @@
package basic
const (
ROLE_MEMBER = 0 // 普通会员
ROLE_MASTER = 1 // 管理员
ROLE_SUPER_MASTER = 2 // 超级管理员
ROLE_CREATEOR = 10 // 创建者
DefaultMemberLimit = 500 // 群组最大成员数
DefaultEnableAnyJoin bool = true // 是否开启无需验证即可加入群组
)
var (
filed string = "passport_identity as identity,nickname,avatar,sex,province,city,area,sign"
)

View File

@@ -0,0 +1,62 @@
package basic
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 创建群组
func Create(ctx context.Context, in *pb.GroupItem) (reply *pb.StatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
record := &models.GroupBasic{
Name: in.GetName(),
Introduce: in.GetIntroduce(),
Avatar: in.GetAvatar(),
Notice: in.GetNotice(),
MemberLimit: DefaultMemberLimit,
EnableAnyJoin: DefaultEnableAnyJoin,
MemberTotal: 1,
}
record.Identity = utils.UUID()
record.PassportID = auth.ID
record.PassportIdentity = auth.Identity
err = impl.DBService.Create(&record).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
member := &models.GroupMember{
GroupID: record.ID,
GroupIdentity: record.Identity,
Role: ROLE_CREATEOR,
}
member.PassportID = auth.ID
member.PassportIdentity = auth.Identity
err = impl.DBService.Create(&member).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: record.Identity,
Timeseq: time.Now().UnixNano(),
}, nil
}

View File

@@ -0,0 +1,33 @@
package basic
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
pb "git.apinb.com/bsm-social/group/pb"
"time"
)
// 解散群组
func Disband(ctx context.Context, in *pb.IdentRequest) (reply *pb.StatusReply, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// valildate request id,identity.
if in.Id == 0 && in.Identity == "" {
return nil, errcode.ErrInvalidArgument
}
// TODO: add your logic code & delete this line.
return &pb.StatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixMilli(),
}, nil
}

View File

@@ -0,0 +1,30 @@
package basic
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 获取群组列表
func Fetch(ctx context.Context, in *pb.Empty) (reply *pb.GroupsReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
groups, err := models.GetMyGroup(auth.ID)
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.GroupsReply{
Total: int32(len(groups)),
}, nil
}

View File

@@ -0,0 +1,26 @@
package basic
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-social/group/internal/impl"
pb "git.apinb.com/bsm-social/group/pb"
)
// 获取群组信息
func Get(ctx context.Context, in *pb.IdentRequest) (reply *pb.GroupItem, err error) {
// parse authorization meta.
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
err = impl.DBService.Where("identity=?", in.Identity).First(&reply).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.GroupItem{}, nil
}

View File

@@ -0,0 +1,46 @@
package basic
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-sdk/core/vars"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 修改群组信息
func Modify(ctx context.Context, in *pb.GroupItem) (reply *pb.StatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
record := &models.GroupBasic{
Name: in.GetName(),
Introduce: in.GetIntroduce(),
Avatar: in.GetAvatar(),
Background: in.GetBackground(),
Notice: in.GetNotice(),
EnableSearchByNumber: in.GetEnableSearchByNumber(),
EnableSearchByName: in.GetEnableSearchByName(),
}
record.Identity = utils.UUID()
err = impl.DBService.Where("identity=? and creator_id=?", in.Identity, auth.ID).UpdateColumns(record).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixMilli(),
}, nil
}

View File

@@ -0,0 +1,22 @@
package basic
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/service"
pb "git.apinb.com/bsm-social/group/pb"
)
// 搜索
func Search(ctx context.Context, in *pb.SearchRequest) (reply *pb.GroupsReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.Keyword == "" {
return nil, errcode.ErrInvalidArgument
}
return &pb.GroupsReply{}, nil
}

View File

@@ -0,0 +1,15 @@
package member
const (
ROLE_MEMBER = 0 // 普通会员
ROLE_MASTER = 1 // 管理员
ROLE_SUPER_MASTER = 2 // 超级管理员
ROLE_CREATEOR = 10 // 创建者
DefaultMemberLimit = 500 // 群组最大成员数
DefaultEnableAnyJoin bool = true // 是否开启无需验证即可加入群组
)
var (
filed string = "passport_identity as identity,nickname,avatar,sex,province,city,area,sign"
)

View File

@@ -0,0 +1,62 @@
package member
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 申请加群
func DoJoin(ctx context.Context, in *pb.DoJoinRequest) (reply *pb.StatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
//生成唯一标识
identity := utils.UUID()
//判断是否需要加群验证
if models.GetGroupEnableAnyJoin(auth.ID, in.Identity) {
// 直接加入群成员
apply := &models.GroupMember{
GroupID: uint(in.Id),
GroupIdentity: in.Identity,
Role: ROLE_MEMBER,
}
apply.Identity = utils.UUID()
apply.PassportID = auth.ID
apply.PassportIdentity = auth.Identity
err = impl.DBService.Create(&apply).Error
} else {
// 写入加群申请表
apply := &models.GroupApply{
FromID: uint(auth.ID),
FromIdentity: auth.Identity,
GroupID: uint(in.Id),
GroupIdentity: in.Identity,
Message: in.Message,
}
apply.Identity = utils.UUID()
err = impl.DBService.Create(&apply).Error
}
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: identity,
Timeseq: time.Now().UnixMilli(),
}, nil
}

View File

@@ -0,0 +1,44 @@
package member
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 踢人
func DoKick(ctx context.Context, in *pb.GroupOPRequest) (reply *pb.StatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// 判断是不是群管理或是创建者
var tc int64
if err = impl.DBService.Model(&models.GroupMember{}).Where("identity=? and role !=0 and passport_id=?", in.GroupIdentity, auth.Identity).Count(&tc).Error; err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
if tc == 0 {
return nil, errcode.ErrPermissionDenied
}
err = impl.DBService.Model(&models.GroupMember{}).Delete("group_identity=? and identity=?", in.GroupIdentity, in.Identity).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
} else {
//更新群组表数据统计
models.UpsetGroupMemberTotal(in.GroupIdentity, "-")
}
return &pb.StatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixMilli(),
}, nil
}

View File

@@ -0,0 +1,47 @@
package member
import (
"context"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 退群
func DoQuit(ctx context.Context, in *pb.GroupOPRequest) (reply *pb.StatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// 判断是不是创建者
var creator_id uint
if err = impl.DBService.Model(&models.GroupBasic{}).Select("creator_id").Where("identity=?", in.GroupIdentity).Scan(&creator_id).Error; err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
if auth.ID == creator_id {
return nil, errcode.ErrPermissionDenied
}
err = impl.DBService.Model(&models.GroupMember{}).Delete("group_identity=? and passport_id=?", in.GroupIdentity, auth.ID).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
} else {
//更新群组表数据统计
models.UpsetGroupMemberTotal(in.GroupIdentity, "-")
}
return &pb.StatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixMilli(),
}, nil
}

View File

@@ -0,0 +1,47 @@
package member
import (
"context"
"strings"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/vars"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 设置或取消管理员
func DoSetManager(ctx context.Context, in *pb.GroupOPRequest) (reply *pb.StatusReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
// 判断是不是创建者
var creator_id uint
if err = impl.DBService.Model(&models.GroupBasic{}).Select("creator_id").Where("identity=?", in.GroupIdentity).Scan(&creator_id).Error; err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
if auth.ID != creator_id {
return nil, errcode.ErrPermissionDenied
}
switch strings.ToUpper(in.Direction) {
case "SET":
//设置管理员
impl.DBService.Model(&models.GroupMember{}).Where("identity=?", in.Identity).UpdateColumn("role", ROLE_MASTER)
case "CANCEL":
//取消管理员
impl.DBService.Model(&models.GroupMember{}).Where("identity=?", in.Identity).UpdateColumn("role", ROLE_MEMBER)
}
return &pb.StatusReply{
Data: vars.OK,
Timeseq: time.Now().UnixMilli(),
}, nil
}

View File

@@ -0,0 +1,34 @@
package member
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 获取群组成员列表
func Fetch(ctx context.Context, in *pb.IdentRequest) (reply *pb.GroupMemberReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
if in.Identity == "" {
return nil, errcode.ErrInvalidArgument
}
members, err := models.GetGroupMember(in.Identity)
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.GroupMemberReply{
Total: int32(len(members)),
}, nil
}

View File

@@ -0,0 +1,68 @@
package member
import (
"context"
"strings"
"time"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 申请加群处理
func JoinDoHandle(ctx context.Context, in *pb.GroupOPRequest) (reply *pb.StatusReply, err error) {
_, err = service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
var identity string
switch strings.ToUpper(in.Direction) {
case "PASS":
var apply models.GroupApply
if err = impl.DBService.Where("identity=?", in.Identity).First(&apply).Error; err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
// 直接加入群成员
identity = utils.UUID()
member := &models.GroupMember{
GroupID: apply.GroupID,
GroupIdentity: apply.GroupIdentity,
Role: 0,
}
member.Identity = utils.UUID()
member.PassportID = apply.FromID
member.PassportIdentity = apply.FromIdentity
if err = impl.DBService.Create(&member).Error; err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
//更新申请表处理结果
impl.DBService.Model(&models.GroupApply{}).Where("identity=?", in.Identity).UpdateColumn("status", 1)
//更新群组表数据统计
models.UpsetGroupMemberTotal(apply.GroupIdentity, "+")
case "REJECT":
//更新申请表处理结果
impl.DBService.Model(&models.GroupApply{}).Where("identity=?", in.Identity).UpdateColumn("status", -1)
}
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
return &pb.StatusReply{
Data: identity,
Timeseq: time.Now().UnixMilli(),
}, nil
}

View File

@@ -0,0 +1,44 @@
package member
import (
"context"
"git.apinb.com/bsm-sdk/core/errcode"
"git.apinb.com/bsm-sdk/core/printer"
"git.apinb.com/bsm-sdk/core/service"
"git.apinb.com/bsm-social/group/internal/impl"
"git.apinb.com/bsm-social/group/internal/models"
pb "git.apinb.com/bsm-social/group/pb"
)
// 申请加群列表
func JoinFetch(ctx context.Context, in *pb.Empty) (reply *pb.JoinFetchReply, err error) {
auth, err := service.ParseMetaCtx(ctx, nil)
if err != nil {
return nil, err
}
fetch := make([]*pb.ApplyJoinGroupItem, 0)
group_ids := models.GetMasterGroup(auth.ID)
if len(group_ids) > 0 {
err = impl.DBService.Model(&models.GroupApply{}).Where("group_id in ", group_ids).Find(&fetch).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
var card = &pb.PassportInfoDetailCard{}
for idx, item := range fetch {
err = impl.DBService.Table("passport_extend").Select(filed).Where("passport_identity = ?", item.From.Identity).First(card).Error
if err != nil {
printer.Error(err.Error())
return nil, errcode.ErrDB
}
fetch[idx].From = card
}
}
return &pb.JoinFetchReply{
Total: int32(len(fetch)),
Applys: fetch,
}, nil
}

View File

@@ -0,0 +1,21 @@
package models
import (
"git.apinb.com/bsm-sdk/core/types"
)
// GroupApply 入群申请
type GroupApply struct {
types.Std_IICUDS
types.Std_Passport
FromID uint `gorm:"column:from_id;not null;" json:"from_id"` //申请人id
FromIdentity string `gorm:"column:from_identity;type:varchar(36);not null;" json:"from_identity"` //申请人identity
GroupID uint `gorm:"column:group_id;not null;" json:"group_id"`
GroupIdentity string `gorm:"column:group_identity;type:varchar(36);not null;" json:"group_identity"`
Message string `gorm:"column:message;type:varchar(255);default:'';" json:"message"`
}
// TableName .
func (ga *GroupApply) TableName() string {
return "relation_group_apply"
}

View File

@@ -0,0 +1,30 @@
package models
import (
"git.apinb.com/bsm-sdk/core/types"
)
// Group .
type GroupBasic struct {
types.Std_IICUDS
types.Std_Passport
Number int64 `gorm:"column:number;not null;" json:"number"` //群号
Avatar string `gorm:"column:avatar;type:varchar(255);default:'';" json:"avatar"`
Name string `gorm:"column:name;type:varchar(255);not null;" json:"name"`
Introduce string `gorm:"column:introduce;type:text;default:'';" json:"introduce"` //简介
MemberLimit int32 `gorm:"column:member_limit;type:smallint;default:100;" json:"member_limit"` // 最大成员数,0代表不限制
Province int32 `gorm:"column:province;default:0;" json:"province"` // 省
City int32 `gorm:"column:city;default:0;" json:"city"` // 市
Area int32 `gorm:"column:area;default:0;" json:"area"` // 区
Notice string `gorm:"column:notice;type:text;default:'';" json:"notice"` // 群公告
Background string `gorm:"column:background;type:varchar(255);default:'';" json:"background"` // 背景
EnableAnyJoin bool `gorm:"column:enable_any_join;" json:"enable_any_join"` // 是否开启无需验证即可加入群组
EnableSearchByNumber bool `gorm:"column:enable_search_by_number;" json:"enable_search_by_number"` // 是否开启群号搜索
EnableSearchByName bool `gorm:"column:enable_search_by_name;" json:"enable_search_by_name"` // 是否开启群名搜索
MemberTotal int32 `gorm:"column:member_total;default:0;" json:"member_total"` // 群组成员数
}
// TableName .
func (group *GroupBasic) TableName() string {
return "group_basic"
}

View File

@@ -0,0 +1,20 @@
package models
import (
"git.apinb.com/bsm-sdk/core/types"
)
// GroupMember 群成员
type GroupMember struct {
types.Std_IICUDS
types.Std_Passport
GroupID uint `gorm:"group_id;not null;" json:"group_id"`
GroupIdentity string `gorm:"column:group_identity;type:varchar(36);not null;" json:"group_identity"` //group_identity
RemarkName string `gorm:"column:remark_name;type:varchar(255);default:'';" json:"remark_name"` //昵称备注
Role int32 `gorm:"role;type:smallint;default:0" json:"role"` //0:普通成员1管理员2超管10创建者
}
// TableName .
func (gm *GroupMember) TableName() string {
return "relation_group_member"
}

View File

@@ -0,0 +1,21 @@
package models
import (
"git.apinb.com/bsm-sdk/core/types"
)
// GroupFiles 群文件
type GroupRes struct {
types.Std_IICUDS
types.Std_Passport
GroupID string `gorm:"column:group_id;type:varchar(50);not null;" json:"group_id"`
Name string `gorm:"column:name;type:varchar(255);not null;" json:"name"`
Introduce string `gorm:"column:introduce;type:varchar(255);default:'';" json:"introduce"` //简介
URL string `gorm:"column:url;type:varchar(255);default:'';" json:"url"`
DownloadNum int64 `gorm:"column:download_num;default:0;" json:"download_num"`
}
// TableName .
func (gf *GroupRes) TableName() string {
return "relation_group_res"
}

View File

@@ -0,0 +1,47 @@
package models
import (
"git.apinb.com/bsm-social/group/internal/impl"
pb "git.apinb.com/bsm-social/group/pb"
"gorm.io/gorm"
)
func InitData() error {
return nil
}
func GetMyGroup(passport_id uint) (groups []*pb.GroupItem, err error) {
sql := `Select group.*,gm.nickname,gm.remark_name,gm.role
From group_member as gm
Left join group on group.id=gm.group_id
Where passport_id=? and deleted_at is null`
err = impl.DBService.Raw(sql, passport_id).Find(&groups).Error
return
}
func GetMasterGroup(passport_id uint) []uint {
var ids []uint
impl.DBService.Model(GroupMember{}).Select("group_id").Where("passport_id=? and role!=0", passport_id).Pluck("group_id", &ids)
return ids
}
func GetGroupMember(group_identity string) (members []*pb.PassportInfoSimpleCard, err error) {
sql := `Select pe.identity,pe.nickname,pe.avatar,pe.sex,gm.remark_name,gm.role
From group_member as gm
Left join passport_extend as pe on pe.passport_id=gm.passport_id
Where group_identity=? and deleted_at is null`
err = impl.DBService.Raw(sql, group_identity).Find(&members).Error
return
}
func GetGroupEnableAnyJoin(passport_id uint, group_identity string) bool {
var is bool = false
impl.DBService.Model(&GroupBasic{}).Select("enable_any_join").Where("createor_id=? and identity=?", passport_id, group_identity).Scan(&is)
return is
}
func UpsetGroupMemberTotal(group_identity string, op string) {
impl.DBService.Model(&GroupBasic{}).Where("identity=?", group_identity).UpdateColumn("member_total", gorm.Expr("member_total ? ?", op, 1))
}

Some files were not shown because too many files have changed in this diff Show More