统计脚本更新
This commit is contained in:
parent
6c5fcf6f8c
commit
922ddc854e
Binary file not shown.
@ -18,6 +18,9 @@ CREATE TABLE IF NOT EXISTS `remain` (
|
||||
SeventhRemain int unsigned NOT NULL DEFAULT '0' COMMENT '七日留存',
|
||||
FourteenthRemain int unsigned NOT NULL DEFAULT '0' COMMENT '十四日留存',
|
||||
ThirtiethRemain int unsigned NOT NULL DEFAULT '0' COMMENT '三十日留存',
|
||||
Recharge decimal(10,2) NOT NULL DEFAULT '0' COMMENT '充值金额',
|
||||
Login int unsigned NOT NULL DEFAULT '0' COMMENT '登录人数',
|
||||
Ext text COMMENT '扩展字段',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE `Date` (`Date`)
|
||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='留存';
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func Statistics() {
|
||||
@ -85,32 +81,8 @@ func DayRemain(now time.Time, Day int) int {
|
||||
}
|
||||
|
||||
func getDb(DbName string) (*sqlx.DB, error) {
|
||||
sshConfig := &ssh.ClientConfig{
|
||||
User: "root",
|
||||
Auth: []ssh.AuthMethod{
|
||||
ssh.Password("-xLX]p!PQ1@SHm`A"),
|
||||
},
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||
}
|
||||
|
||||
// 连接到 SSH 服务器
|
||||
sshConn, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", "8.155.14.94", 22), sshConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to dial SSH: %v", err)
|
||||
}
|
||||
|
||||
// 创建到 MySQL 服务器的隧道
|
||||
mysqlConn, err := sshConn.Dial("tcp", fmt.Sprintf("%s:%d", "rm-f8zd2030feam53n43.mysql.rds.aliyuncs.com", 3306))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to dial MySQL: %v", err)
|
||||
}
|
||||
|
||||
// 注册 MySQL 驱动
|
||||
mysql.RegisterDialContext("mysql+tcp", func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
return mysqlConn, nil
|
||||
})
|
||||
// 连接到 MySQL 数据库
|
||||
dsn := fmt.Sprintf("%s:%s@mysql+tcp(%s:%d)/%s", "root", "Z4rf7eZZe500dxa", "rm-f8zd2030feam53n43.mysql.rds.aliyuncs.com", 3306, DbName)
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", "root", "Z4rf7eZZe500dxa", "rm-f8zd2030feam53n43.mysql.rds.aliyuncs.com", 3306, DbName)
|
||||
db, err := sqlx.Open("mysql", dsn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open MySQL: %v", err)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user