-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95952da
commit 2dfccd2
Showing
507 changed files
with
9,020 additions
and
27,628 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/TremblingV5/DouTok/applications/comment/dal/model" | ||
"github.com/TremblingV5/DouTok/applications/comment/misc" | ||
"github.com/TremblingV5/DouTok/applications/comment/service" | ||
) | ||
|
||
func main() { | ||
misc.InitViperConfig() | ||
|
||
service.InitDb( | ||
misc.GetConfig("MySQL.Username"), | ||
misc.GetConfig("MySQL.Password"), | ||
misc.GetConfig("MySQL.Host"), | ||
misc.GetConfig("MySQL.Port"), | ||
misc.GetConfig("MySQL.Database"), | ||
) | ||
|
||
service.DB.AutoMigrate(&model.Comment{}, &model.CommentCount{}) | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...s/commentDomain/dal/hbModel/comment_hb.go → applications/comment/dal/model/comment_hb.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package hbModel | ||
package model | ||
|
||
import ( | ||
"encoding/binary" | ||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...entDomain/dal/query/comment_counts.gen.go → ...s/comment/dal/query/comment_counts.gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...s/commentDomain/dal/query/comments.gen.go → ...cations/comment/dal/query/comments.gen.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/TremblingV5/DouTok/applications/comment/misc" | ||
"github.com/TremblingV5/DouTok/applications/comment/pack" | ||
"github.com/TremblingV5/DouTok/applications/comment/service" | ||
"github.com/TremblingV5/DouTok/kitex_gen/comment" | ||
"github.com/TremblingV5/DouTok/pkg/utils" | ||
) | ||
|
||
func (s *CommentServiceImpl) CommentAction(ctx context.Context, req *comment.DouyinCommentActionRequest) (resp *comment.DouyinCommentActionResponse, err error) { | ||
if result := misc.CheckCommentActionArgs(req); !result { | ||
return pack.PackCommentActionResp(int32(misc.ParamsErr.ErrCode), misc.ParamsErr.ErrMsg, nil, req.UserId) | ||
} | ||
|
||
// 判断请求的动作,1为新加评论,2为删除评论 | ||
if req.ActionType == 1 { | ||
result, err := service.AddComment( | ||
req.VideoId, req.UserId, utils.GetSnowFlakeId().Int64(), 0, 0, req.CommentText, | ||
) | ||
if err != nil { | ||
return pack.PackCommentActionResp(int32(misc.SystemErr.ErrCode), misc.SystemErr.ErrMsg, nil, req.UserId) | ||
} | ||
return pack.PackCommentActionResp(int32(misc.Success.ErrCode), misc.Success.ErrMsg, result, req.UserId) | ||
} else if req.ActionType == 2 { | ||
errNo, err := service.RmComment(req.UserId, req.CommentId) | ||
if err != nil { | ||
return pack.PackCommentActionResp(int32(errNo.ErrCode), errNo.ErrMsg, nil, req.UserId) | ||
} | ||
return pack.PackCommentActionResp(int32(misc.Success.ErrCode), misc.Success.ErrMsg, nil, req.UserId) | ||
} else { | ||
return pack.PackCommentActionResp(int32(misc.BindingErr.ErrCode), misc.BindingErr.ErrMsg, nil, req.UserId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/TremblingV5/DouTok/applications/comment/misc" | ||
"github.com/TremblingV5/DouTok/applications/comment/pack" | ||
"github.com/TremblingV5/DouTok/applications/comment/service" | ||
"github.com/TremblingV5/DouTok/kitex_gen/comment" | ||
) | ||
|
||
func (s *CommentServiceImpl) CommentCount(ctx context.Context, req *comment.DouyinCommentCountRequest) (resp *comment.DouyinCommentCountResponse, err error) { | ||
if len(req.VideoIdList) == 0 { | ||
return pack.PackCommentCountResp(int32(misc.ListEmptyErr.ErrCode), misc.ListEmptyErr.ErrMsg, nil) | ||
} | ||
|
||
res, errNo, err := service.CountComment(req.VideoIdList...) | ||
if err != nil { | ||
return pack.PackCommentCountResp(int32(errNo.ErrCode), errNo.ErrMsg, nil) | ||
} | ||
|
||
return pack.PackCommentCountResp(int32(errNo.ErrCode), errNo.ErrMsg, res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/TremblingV5/DouTok/applications/comment/misc" | ||
"github.com/TremblingV5/DouTok/applications/comment/pack" | ||
"github.com/TremblingV5/DouTok/applications/comment/service" | ||
"github.com/TremblingV5/DouTok/kitex_gen/comment" | ||
) | ||
|
||
func (s *CommentServiceImpl) CommentList(ctx context.Context, req *comment.DouyinCommentListRequest) (resp *comment.DouyinCommentListResponse, err error) { | ||
if !misc.CheckCommentListArgs(req) { | ||
return pack.PackCommentListResp(int32(misc.VideoIdErr.ErrCode), misc.VideoIdErr.ErrMsg, nil) | ||
} | ||
|
||
res, errNo, err := service.ListComment(req.VideoId) | ||
if err != nil { | ||
return pack.PackCommentListResp(int32(errNo.ErrCode), errNo.ErrMsg, nil) | ||
} | ||
|
||
return pack.PackCommentListResp(int32(misc.Success.ErrCode), misc.Success.ErrMsg, res) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package handler | ||
|
||
type CommentServiceImpl struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/TremblingV5/DouTok/applications/comment/handler" | ||
"github.com/TremblingV5/DouTok/applications/comment/misc" | ||
"github.com/TremblingV5/DouTok/applications/comment/rpc" | ||
"github.com/TremblingV5/DouTok/config/configStruct" | ||
"github.com/TremblingV5/DouTok/applications/comment/service" | ||
"github.com/TremblingV5/DouTok/kitex_gen/comment/commentservice" | ||
"github.com/TremblingV5/DouTok/pkg/DouTokContext" | ||
"github.com/TremblingV5/DouTok/pkg/DouTokLogger" | ||
"github.com/TremblingV5/DouTok/pkg/configurator" | ||
"github.com/TremblingV5/DouTok/pkg/constants" | ||
"github.com/TremblingV5/DouTok/pkg/services" | ||
"go.uber.org/zap" | ||
"github.com/TremblingV5/DouTok/pkg/dlog" | ||
"github.com/TremblingV5/DouTok/pkg/initHelper" | ||
) | ||
|
||
type Config struct { | ||
configStruct.BaseConfig `envPrefix:"DOUTOK_COMMENT_"` | ||
Jwt configStruct.Jwt `envPrefix:"DOUTOK_COMMENT_"` | ||
Logger configStruct.Logger `envPrefix:"DOUTOK_COMMENT_"` | ||
} | ||
|
||
var ( | ||
logger *zap.Logger | ||
config = &Config{} | ||
Logger = dlog.InitLog(3) | ||
) | ||
|
||
func init() { | ||
func Init() { | ||
misc.InitViperConfig() | ||
|
||
ctx := context.Background() | ||
_, err := configurator.Load(config, "DOUTOK_COMMENT", "comment") | ||
logger = DouTokLogger.InitLogger(config.Logger) | ||
DouTokContext.DefaultLogger = logger | ||
DouTokContext.AddLoggerToContext(ctx, logger) | ||
if err != nil { | ||
logger.Fatal("could not load env variables", zap.Error(err), zap.Any("config", config)) | ||
} | ||
service.Init() | ||
|
||
rpc.InitPRCClient() | ||
|
||
go service.UpdateComCountMap() | ||
go service.UpdateComTotalCntMap() | ||
} | ||
|
||
func main() { | ||
options, shutdown := services.InitRPCServerArgs(constants.COMMENT_SERVER_NAME, config.BaseConfig) | ||
Init() | ||
|
||
options, shutdown := initHelper.InitRPCServerArgs(misc.Config) | ||
defer shutdown() | ||
|
||
svr := commentservice.NewServer( | ||
handler.New(rpc.New(services.InitRPCClientArgs(constants.COMMENT_SERVER_NAME, config.Etcd))), | ||
options..., | ||
new(handler.CommentServiceImpl), | ||
options... | ||
) | ||
|
||
if err := svr.Run(); err != nil { | ||
logger.Fatal("run server err", zap.Error(err)) | ||
Logger.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package misc | ||
|
||
import "github.com/TremblingV5/DouTok/kitex_gen/comment" | ||
|
||
func CheckCommentActionArgs(req *comment.DouyinCommentActionRequest) bool { | ||
return req.CommentText != "" | ||
} | ||
|
||
func CheckCommentListArgs(req *comment.DouyinCommentListRequest) bool { | ||
return req.VideoId >= 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package misc | ||
|
||
import "github.com/TremblingV5/DouTok/pkg/dtviper" | ||
|
||
var Config *dtviper.Config | ||
|
||
func InitViperConfig() { | ||
config := dtviper.ConfigInit(ViperConfigEnvPrefix, ViperConfigEnvFilename) | ||
Config = config | ||
} | ||
|
||
func GetConfig(key string) string { | ||
return Config.Viper.GetString(key) | ||
} | ||
|
||
func GetConfigNum(key string) int64 { | ||
return Config.Viper.GetInt64(key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package misc | ||
|
||
const ( | ||
ViperConfigEnvPrefix = "DOUTOK_COMMENT" | ||
ViperConfigEnvFilename = "comment" | ||
|
||
ComCntCache = "comcntcache" | ||
ComTotalCntCache = "comtotalcntcache" | ||
) |
Oops, something went wrong.