Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aon-tg-messenger
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
aon-tg-messenger
Commits
1f374aed
Commit
1f374aed
authored
Aug 05, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
1d224a83
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
77 additions
and
37 deletions
+77
-37
config.toml
config.toml
+9
-8
config.go
config/config.go
+3
-2
dao.go
dao/dao.go
+17
-7
db.go
dao/db.go
+8
-5
docker-compose.yml
docker-compose.yml
+2
-0
go.mod
go.mod
+6
-2
go.sum
go.sum
+12
-5
db.go
model/db/db.go
+18
-6
user.go
server/user.go
+2
-2
No files found.
config.toml
View file @
1f374aed
debug
=
true
debug
=
true
[
my
sql]
[
pg
sql]
host
=
"a
on-db
"
host
=
"a
ws-0-ap-northeast-1.pooler.supabase.com
"
port
=
3306
port
=
5432
user
=
"
root
"
user
=
"
postgres.vbxtvjffhsirnyxjcuku
"
password
=
"
XN2UARuys3zy4Oux
"
password
=
""
database
=
"
tg
"
database
=
"
postgres
"
max_conn
=
10
max_conn
=
3
max_idle_conn
=
2
max_idle_conn
=
3
enable_log
=
true
enable_log
=
true
cert_file
=
"db.crt"
[server]
[server]
listen
=
"0.0.0.0:8080"
listen
=
"0.0.0.0:8080"
...
...
config/config.go
View file @
1f374aed
...
@@ -8,12 +8,12 @@ import (
...
@@ -8,12 +8,12 @@ import (
type
Config
struct
{
type
Config
struct
{
Debug
bool
`toml:"debug"`
Debug
bool
`toml:"debug"`
MySQL
MysqlConfig
`toml:"my
sql"`
PGSQL
PGSQLConfig
`toml:"pg
sql"`
Server
ServerConfig
`toml:"server"`
Server
ServerConfig
`toml:"server"`
TGBot
TGBotConfig
`toml:"tg_bot"`
TGBot
TGBotConfig
`toml:"tg_bot"`
}
}
type
Mysql
Config
struct
{
type
PGSQL
Config
struct
{
Host
string
`toml:"host"`
Host
string
`toml:"host"`
Port
int
`toml:"port"`
Port
int
`toml:"port"`
User
string
`toml:"user"`
User
string
`toml:"user"`
...
@@ -22,6 +22,7 @@ type MysqlConfig struct {
...
@@ -22,6 +22,7 @@ type MysqlConfig struct {
MaxConn
int
`toml:"max_conn"`
MaxConn
int
`toml:"max_conn"`
MaxIdleConn
int
`toml:"max_idle_conn"`
MaxIdleConn
int
`toml:"max_idle_conn"`
EnableLog
bool
`toml:"enable_log"`
EnableLog
bool
`toml:"enable_log"`
CertFile
string
`toml:"cert_file"`
}
}
type
ServerConfig
struct
{
type
ServerConfig
struct
{
...
...
dao/dao.go
View file @
1f374aed
...
@@ -6,7 +6,7 @@ import (
...
@@ -6,7 +6,7 @@ import (
dbModel
"sdk_api/model/db"
dbModel
"sdk_api/model/db"
"time"
"time"
"gorm.io/driver/
mysql
"
"gorm.io/driver/
postgres
"
"gorm.io/gorm"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
"gorm.io/gorm/schema"
...
@@ -22,14 +22,24 @@ func New(_c *config.Config) (dao *Dao, err error) {
...
@@ -22,14 +22,24 @@ func New(_c *config.Config) (dao *Dao, err error) {
c
:
_c
,
c
:
_c
,
}
}
dsn
:=
fmt
.
Sprintf
(
"%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True"
,
// dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True",
_c
.
MySQL
.
User
,
_c
.
MySQL
.
Password
,
_c
.
MySQL
.
Host
,
_c
.
MySQL
.
Port
,
_c
.
MySQL
.
Database
)
// _c.MySQL.User, _c.MySQL.Password, _c.MySQL.Host, _c.MySQL.Port, _c.MySQL.Database)
// dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=verify-ca sslrootcert=ca.crt",
dsn
:=
fmt
.
Sprintf
(
"host=%s user=%s password=%s dbname=%s port=%d"
,
_c
.
PGSQL
.
Host
,
_c
.
PGSQL
.
User
,
_c
.
PGSQL
.
Password
,
_c
.
PGSQL
.
Database
,
_c
.
PGSQL
.
Port
,
)
if
_c
.
PGSQL
.
CertFile
!=
""
{
dsn
=
fmt
.
Sprintf
(
"%s sslmode=require sslrootcert=%s"
,
dsn
,
_c
.
PGSQL
.
CertFile
)
}
lgr
:=
logger
.
Default
lgr
:=
logger
.
Default
if
_c
.
My
SQL
.
EnableLog
{
if
_c
.
PG
SQL
.
EnableLog
{
lgr
=
logger
.
Default
.
LogMode
(
logger
.
Info
)
lgr
=
logger
.
Default
.
LogMode
(
logger
.
Info
)
}
}
dao
.
db
,
err
=
gorm
.
Open
(
mysql
.
Open
(
dsn
),
&
gorm
.
Config
{
dao
.
db
,
err
=
gorm
.
Open
(
postgres
.
Open
(
dsn
),
&
gorm
.
Config
{
NamingStrategy
:
schema
.
NamingStrategy
{
NamingStrategy
:
schema
.
NamingStrategy
{
SingularTable
:
true
,
SingularTable
:
true
,
},
},
...
@@ -42,8 +52,8 @@ func New(_c *config.Config) (dao *Dao, err error) {
...
@@ -42,8 +52,8 @@ func New(_c *config.Config) (dao *Dao, err error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
sqlDB
.
SetMaxOpenConns
(
_c
.
My
SQL
.
MaxConn
)
sqlDB
.
SetMaxOpenConns
(
_c
.
PG
SQL
.
MaxConn
)
sqlDB
.
SetMaxIdleConns
(
_c
.
My
SQL
.
MaxIdleConn
)
sqlDB
.
SetMaxIdleConns
(
_c
.
PG
SQL
.
MaxIdleConn
)
sqlDB
.
SetConnMaxIdleTime
(
time
.
Hour
)
sqlDB
.
SetConnMaxIdleTime
(
time
.
Hour
)
err
=
dao
.
db
.
AutoMigrate
(
&
dbModel
.
User
{},
&
dbModel
.
Active
{},
&
dbModel
.
ChatGroup
{})
err
=
dao
.
db
.
AutoMigrate
(
&
dbModel
.
User
{},
&
dbModel
.
Active
{},
&
dbModel
.
ChatGroup
{})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
dao/db.go
View file @
1f374aed
package
dao
package
dao
import
(
import
(
"fmt"
dbModel
"sdk_api/model/db"
dbModel
"sdk_api/model/db"
"gorm.io/gorm"
"gorm.io/gorm"
...
@@ -9,6 +10,7 @@ import (
...
@@ -9,6 +10,7 @@ import (
func
(
d
*
Dao
)
CreateUser
(
user
*
dbModel
.
User
)
(
err
error
)
{
func
(
d
*
Dao
)
CreateUser
(
user
*
dbModel
.
User
)
(
err
error
)
{
return
d
.
db
.
Clauses
(
clause
.
OnConflict
{
return
d
.
db
.
Clauses
(
clause
.
OnConflict
{
Columns
:
[]
clause
.
Column
{{
Name
:
"user_id"
},
{
Name
:
"chat_id"
}},
DoUpdates
:
clause
.
Assignments
(
map
[
string
]
interface
{}{
"left_at"
:
gorm
.
Expr
(
"NULL"
)}),
DoUpdates
:
clause
.
Assignments
(
map
[
string
]
interface
{}{
"left_at"
:
gorm
.
Expr
(
"NULL"
)}),
})
.
Create
(
user
)
.
Error
})
.
Create
(
user
)
.
Error
}
}
...
@@ -16,14 +18,15 @@ func (d *Dao) CreateUser(user *dbModel.User) (err error) {
...
@@ -16,14 +18,15 @@ func (d *Dao) CreateUser(user *dbModel.User) (err error) {
func
(
d
*
Dao
)
IncrMessageCount
(
a
*
dbModel
.
Active
)
(
err
error
)
{
func
(
d
*
Dao
)
IncrMessageCount
(
a
*
dbModel
.
Active
)
(
err
error
)
{
a
.
MsgCount
=
1
a
.
MsgCount
=
1
return
d
.
db
.
Clauses
(
clause
.
OnConflict
{
return
d
.
db
.
Clauses
(
clause
.
OnConflict
{
DoUpdates
:
clause
.
Assignments
(
map
[
string
]
interface
{}{
"msg_count"
:
gorm
.
Expr
(
"msg_count + ?"
,
1
)}),
Columns
:
[]
clause
.
Column
{{
Name
:
"user_id"
},
{
Name
:
"chat_id"
},
{
Name
:
"unix_day"
}},
DoUpdates
:
clause
.
Assignments
(
map
[
string
]
interface
{}{
"msg_count"
:
gorm
.
Expr
(
fmt
.
Sprintf
(
"%s.msg_count + ?"
,
a
.
TableName
()),
1
)}),
})
.
Create
(
a
)
.
Error
})
.
Create
(
a
)
.
Error
}
}
func
(
d
*
Dao
)
GetUserActiveMsgCount
(
userId
,
chatId
,
unixDay
int
)
(
count
int
,
err
error
)
{
func
(
d
*
Dao
)
GetUserActiveMsgCount
(
userId
,
chatId
,
unixDay
int
)
(
count
int
,
err
error
)
{
a
:=
dbModel
.
Active
{}
a
:=
dbModel
.
Active
{}
err
=
d
.
db
.
Model
(
&
dbModel
.
Active
{})
.
err
=
d
.
db
.
Model
(
&
dbModel
.
Active
{})
.
Where
(
"
`user_id` = ? AND `chat_id` = ? AND `unix_day`
= ?"
,
userId
,
chatId
,
unixDay
)
.
Where
(
"
user_id = ? AND chat_id = ? AND unix_day
= ?"
,
userId
,
chatId
,
unixDay
)
.
First
(
&
a
)
.
Error
First
(
&
a
)
.
Error
if
err
==
gorm
.
ErrRecordNotFound
{
if
err
==
gorm
.
ErrRecordNotFound
{
...
@@ -36,7 +39,7 @@ func (d *Dao) GetUserActiveMsgCount(userId, chatId, unixDay int) (count int, err
...
@@ -36,7 +39,7 @@ func (d *Dao) GetUserActiveMsgCount(userId, chatId, unixDay int) (count int, err
func
(
d
*
Dao
)
UserExist
(
userId
,
chatId
int
)
(
exist
bool
,
err
error
)
{
func
(
d
*
Dao
)
UserExist
(
userId
,
chatId
int
)
(
exist
bool
,
err
error
)
{
a
:=
dbModel
.
User
{}
a
:=
dbModel
.
User
{}
err
=
d
.
db
.
Model
(
&
dbModel
.
User
{})
.
err
=
d
.
db
.
Model
(
&
dbModel
.
User
{})
.
Where
(
"
`user_id` = ? AND `chat_id` = ? AND `left_at`
IS NULL"
,
userId
,
chatId
)
.
Where
(
"
user_id = ? AND chat_id = ? AND left_at
IS NULL"
,
userId
,
chatId
)
.
First
(
&
a
)
.
Error
First
(
&
a
)
.
Error
if
err
==
gorm
.
ErrRecordNotFound
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
false
,
nil
return
false
,
nil
...
@@ -46,14 +49,14 @@ func (d *Dao) UserExist(userId, chatId int) (exist bool, err error) {
...
@@ -46,14 +49,14 @@ func (d *Dao) UserExist(userId, chatId int) (exist bool, err error) {
func
(
d
*
Dao
)
UserLeft
(
userId
,
chatId
int
)
(
err
error
)
{
func
(
d
*
Dao
)
UserLeft
(
userId
,
chatId
int
)
(
err
error
)
{
return
d
.
db
.
Model
(
&
dbModel
.
User
{})
.
return
d
.
db
.
Model
(
&
dbModel
.
User
{})
.
Where
(
"
`user_id` = ? AND `chat_id` = ? AND `left_at`
IS NULL"
,
userId
,
chatId
)
.
Where
(
"
user_id = ? AND chat_id = ? AND left_at
IS NULL"
,
userId
,
chatId
)
.
Update
(
"left_at"
,
gorm
.
Expr
(
"NOW()"
))
.
Error
Update
(
"left_at"
,
gorm
.
Expr
(
"NOW()"
))
.
Error
}
}
func
(
d
*
Dao
)
IsSupportedChat
(
chatId
int
)
(
exist
bool
,
err
error
)
{
func
(
d
*
Dao
)
IsSupportedChat
(
chatId
int
)
(
exist
bool
,
err
error
)
{
a
:=
dbModel
.
ChatGroup
{}
a
:=
dbModel
.
ChatGroup
{}
err
=
d
.
db
.
Model
(
&
dbModel
.
ChatGroup
{})
.
err
=
d
.
db
.
Model
(
&
dbModel
.
ChatGroup
{})
.
Where
(
"
`chat_id`
= ?"
,
chatId
)
.
Where
(
"
chat_id
= ?"
,
chatId
)
.
First
(
&
a
)
.
Error
First
(
&
a
)
.
Error
if
err
==
gorm
.
ErrRecordNotFound
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
false
,
nil
return
false
,
nil
...
...
docker-compose.yml
View file @
1f374aed
...
@@ -15,6 +15,7 @@ services:
...
@@ -15,6 +15,7 @@ services:
volumes
:
volumes
:
-
./conf/tg-messenger/config.toml:/config.toml
-
./conf/tg-messenger/config.toml:/config.toml
-
./data/tg-messenger/db.crt:/app/db.crt
-
./data/tg-messenger/api-log:/app
-
./data/tg-messenger/api-log:/app
command
:
command
:
-
"
/bin/sh"
-
"
/bin/sh"
...
@@ -33,6 +34,7 @@ services:
...
@@ -33,6 +34,7 @@ services:
volumes
:
volumes
:
-
./conf/tg-messenger/config.toml:/config.toml
-
./conf/tg-messenger/config.toml:/config.toml
-
./data/tg-messenger/db.crt:/app/db.crt
-
./data/tg-messenger/messenger-log:/app
-
./data/tg-messenger/messenger-log:/app
command
:
command
:
-
"
/bin/sh"
-
"
/bin/sh"
...
...
go.mod
View file @
1f374aed
...
@@ -10,7 +10,7 @@ require (
...
@@ -10,7 +10,7 @@ require (
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.9.0
github.com/tidwall/gjson v1.17.1
github.com/tidwall/gjson v1.17.1
gorm.io/driver/
mysql v1.5.6
gorm.io/driver/
postgres v1.5.9
gorm.io/gorm v1.25.10
gorm.io/gorm v1.25.10
)
)
...
@@ -24,8 +24,11 @@ require (
...
@@ -24,8 +24,11 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.5 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/json-iterator/go v1.1.12 // indirect
...
@@ -43,6 +46,7 @@ require (
...
@@ -43,6 +46,7 @@ require (
golang.org/x/arch v0.8.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
google.golang.org/protobuf v1.34.1 // indirect
...
...
go.sum
View file @
1f374aed
...
@@ -28,8 +28,6 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
...
@@ -28,8 +28,6 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
...
@@ -39,6 +37,14 @@ github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVI
...
@@ -39,6 +37,14 @@ github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVI
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
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-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
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/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 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
...
@@ -100,6 +106,8 @@ golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
...
@@ -100,6 +106,8 @@ golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
...
@@ -117,9 +125,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
...
@@ -117,9 +125,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.6 h1:Ld4mkIickM+EliaQZQx3uOJDJHtrd70MxAUqWqlx3Y8=
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
...
...
model/db/db.go
View file @
1f374aed
...
@@ -7,16 +7,20 @@ import (
...
@@ -7,16 +7,20 @@ import (
)
)
type
User
struct
{
type
User
struct
{
Id
int
`gorm:"primaryKey"`
Id
int
`gorm:"primaryKey
;autoIncrement
"`
UserId
int
`gorm:"type:int;uniqueIndex:uidx_uid_cid;not null;comment:telegram用户id"`
UserId
int
`gorm:"type:int;uniqueIndex:uidx_uid_cid;not null;comment:telegram用户id"`
Username
string
`gorm:"type:
varchar(255)
;not null;comment:telegram用户名"`
Username
string
`gorm:"type:
text
;not null;comment:telegram用户名"`
ChatId
int
`gorm:"type:int;uniqueIndex:uidx_uid_cid;not null;comment:telegram群id"`
ChatId
int
`gorm:"type:int;uniqueIndex:uidx_uid_cid;not null;comment:telegram群id"`
LeftAt
sql
.
NullTime
`gorm:"index;comment:退出时间"`
LeftAt
sql
.
NullTime
`gorm:"index;comment:退出时间"`
gorm
.
Model
gorm
.
Model
}
}
func
(
*
User
)
TableName
()
string
{
return
"telegram_task.user"
}
type
Active
struct
{
type
Active
struct
{
Id
int
`gorm:"primaryKey"`
Id
int
`gorm:"primaryKey
;autoIncrement
"`
UserId
int
`gorm:"type:int;uniqueIndex:uidx_uid_cid_day;not null;comment:telegram用户id"`
UserId
int
`gorm:"type:int;uniqueIndex:uidx_uid_cid_day;not null;comment:telegram用户id"`
ChatId
int
`gorm:"type:int;uniqueIndex:uidx_uid_cid_day;not null;comment:telegram群id"`
ChatId
int
`gorm:"type:int;uniqueIndex:uidx_uid_cid_day;not null;comment:telegram群id"`
UnixDay
int
`gorm:"type:int;not null;uniqueIndex:uidx_uid_cid_day;comment:unix day"`
UnixDay
int
`gorm:"type:int;not null;uniqueIndex:uidx_uid_cid_day;comment:unix day"`
...
@@ -24,10 +28,18 @@ type Active struct {
...
@@ -24,10 +28,18 @@ type Active struct {
gorm
.
Model
gorm
.
Model
}
}
func
(
*
Active
)
TableName
()
string
{
return
"telegram_task.active"
}
type
ChatGroup
struct
{
type
ChatGroup
struct
{
Id
int
`gorm:"primaryKey"`
Id
int
`gorm:"primaryKey
;autoIncrement
"`
ChatId
int
`gorm:"type:int;uniqueIndex;not null;comment:telegram群id"`
ChatId
int
`gorm:"type:int;uniqueIndex;not null;comment:telegram群id"`
ChatTitle
string
`gorm:"type:
varchar(255)
;not null;comment:telegram群名"`
ChatTitle
string
`gorm:"type:
text
;not null;comment:telegram群名"`
Description
string
`gorm:"type:
varchar(255)
;comment:群描述"`
Description
string
`gorm:"type:
text
;comment:群描述"`
gorm
.
Model
gorm
.
Model
}
}
func
(
*
ChatGroup
)
TableName
()
string
{
return
"telegram_task.chat_group"
}
server/user.go
View file @
1f374aed
...
@@ -24,7 +24,7 @@ func isJoined(c *gin.Context) {
...
@@ -24,7 +24,7 @@ func isJoined(c *gin.Context) {
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
return
return
}
}
c
.
JSON
(
200
,
gin
.
H
{
"joined"
:
joined
}
)
c
.
JSON
(
200
,
withSuccess
(
gin
.
H
{
"joined"
:
joined
})
)
return
return
}
}
...
@@ -45,5 +45,5 @@ func active(c *gin.Context) {
...
@@ -45,5 +45,5 @@ func active(c *gin.Context) {
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
return
return
}
}
c
.
JSON
(
200
,
gin
.
H
{
"msgCount"
:
msgCount
}
)
c
.
JSON
(
200
,
withSuccess
(
gin
.
H
{
"msgCount"
:
msgCount
})
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment