* statistics user register

* refactor: router change

* minio init

---------

Co-authored-by: withchao <993506633@qq.com>
Co-authored-by: Gordon <1432970085@qq.com>
pull/469/head
WangchuXiao 1 year ago committed by GitHub
parent e50b8bd8f1
commit 941c1f954e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -34,15 +34,16 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
r.GET("/metrics", prome.PrometheusHandler()) r.GET("/metrics", prome.PrometheusHandler())
} }
ParseToken := mw.GinParseToken(rdb) ParseToken := mw.GinParseToken(rdb)
userRouterGroup := r.Group("/user", ParseToken) userRouterGroup := r.Group("/user")
{ {
userRouterGroup.POST("/update_user_info", u.UpdateUserInfo) userRouterGroup.POST("/user_register", u.UserRegister)
userRouterGroup.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt) userRouterGroup.POST("/update_user_info", ParseToken, u.UpdateUserInfo)
userRouterGroup.POST("/get_users_info", u.GetUsersPublicInfo) userRouterGroup.POST("/set_global_msg_recv_opt", ParseToken, u.SetGlobalRecvMessageOpt)
userRouterGroup.POST("/get_all_users_uid", u.GetAllUsersID) userRouterGroup.POST("/get_users_info", ParseToken, u.GetUsersPublicInfo)
userRouterGroup.POST("/account_check", u.AccountCheck) userRouterGroup.POST("/get_all_users_uid", ParseToken, u.GetAllUsersID)
userRouterGroup.POST("/get_users", u.GetUsers) userRouterGroup.POST("/account_check", ParseToken, u.AccountCheck)
userRouterGroup.POST("/get_users_online_status", u.GetUsersOnlineStatus) userRouterGroup.POST("/get_users", ParseToken, u.GetUsers)
userRouterGroup.POST("/get_users_online_status", ParseToken, u.GetUsersOnlineStatus)
} }
//friend routing group //friend routing group
friendRouterGroup := r.Group("/friend", ParseToken) friendRouterGroup := r.Group("/friend", ParseToken)

@ -33,10 +33,11 @@ func NewMinioInterface() (Interface, error) {
} }
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20) ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
defer cancel() defer cancel()
initBucket := func(ctx context.Context) error {
for _, bucket := range utils.Distinct([]string{conf.TempBucket, conf.DataBucket}) { for _, bucket := range utils.Distinct([]string{conf.TempBucket, conf.DataBucket}) {
exists, err := client.BucketExists(ctx, bucket) exists, err := client.BucketExists(ctx, bucket)
if err != nil { if err != nil {
return nil, fmt.Errorf("minio bucket %s exists %w", bucket, err) return fmt.Errorf("minio bucket %s exists %w", bucket, err)
} }
if exists { if exists {
continue continue
@ -46,9 +47,14 @@ func NewMinioInterface() (Interface, error) {
ObjectLocking: conf.IsDistributedMod, ObjectLocking: conf.IsDistributedMod,
} }
if err := client.MakeBucket(ctx, bucket, opt); err != nil { if err := client.MakeBucket(ctx, bucket, opt); err != nil {
return nil, fmt.Errorf("minio make bucket %s %w", bucket, err) return fmt.Errorf("minio make bucket %s %w", bucket, err)
} }
} }
return nil
}
if err := initBucket(ctx); err != nil {
fmt.Println("minio init error:", err)
}
return &minioImpl{ return &minioImpl{
client: client, client: client,
tempBucket: conf.TempBucket, tempBucket: conf.TempBucket,

@ -74,7 +74,7 @@ func (u *UserGorm) CountTotal(ctx context.Context) (count int64, err error) {
func (u *UserGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) { func (u *UserGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) {
var res []struct { var res []struct {
Date string `gorm:"column:date"` Date time.Time `gorm:"column:date"`
Count int64 `gorm:"column:count"` Count int64 `gorm:"column:count"`
} }
err := u.db(ctx).Model(&relation.UserModel{}).Select("DATE(create_time) AS date, count(1) AS count").Where("create_time >= ? and create_time < ?", start, end).Group("date").Find(&res).Error err := u.db(ctx).Model(&relation.UserModel{}).Select("DATE(create_time) AS date, count(1) AS count").Where("create_time >= ? and create_time < ?", start, end).Group("date").Find(&res).Error
@ -83,7 +83,7 @@ func (u *UserGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time,
} }
v := make(map[string]int64) v := make(map[string]int64)
for _, r := range res { for _, r := range res {
v[r.Date] = r.Count v[r.Date.Format("2006-01-02")] = r.Count
} }
return v, nil return v, nil
} }

Loading…
Cancel
Save