├── .gitignore ├── uuBot.png ├── main.go ├── go.mod ├── service ├── config.go ├── db.go └── bot.go ├── LICENSE ├── README.md └── go.sum /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .vacode 4 | 5 | 6 | -------------------------------------------------------------------------------- /uuBot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iloldeGitHub/v2board-bot-1/HEAD/uuBot.png -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/miyaUU/v2board-bot/service" 5 | ) 6 | 7 | func main() { 8 | service.InitDB() 9 | service.Start() 10 | } 11 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/miyaUU/v2board-bot 2 | 3 | go 1.17 4 | 5 | require ( 6 | gopkg.in/tucnak/telebot.v2 v2.5.0 7 | gopkg.in/yaml.v2 v2.4.0 8 | gorm.io/driver/mysql v1.2.2 9 | gorm.io/gorm v1.22.4 10 | ) 11 | 12 | require ( 13 | github.com/go-sql-driver/mysql v1.6.0 // indirect 14 | github.com/jinzhu/inflection v1.0.0 // indirect 15 | github.com/jinzhu/now v1.1.3 // indirect 16 | github.com/pkg/errors v0.8.1 // indirect 17 | ) 18 | -------------------------------------------------------------------------------- /service/config.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "fmt" 5 | "gopkg.in/yaml.v2" 6 | "io/ioutil" 7 | "os" 8 | ) 9 | 10 | type Conf struct { 11 | Bot BotConf `yaml:"bot"` 12 | Database DatabaseConf `yaml:"database"` 13 | } 14 | 15 | type BotConf struct { 16 | Token string `yaml:"token"` 17 | Name string `yaml:"name"` 18 | Byte int64 `yaml:"byte"` 19 | } 20 | type DatabaseConf struct { 21 | Host string `yaml:"host"` 22 | Port int `yaml:"port"` 23 | Name string `yaml:"name"` 24 | Username string `yaml:"username"` 25 | Password string `yaml:"password"` 26 | } 27 | 28 | func (c *Conf) GetConfig() *Conf { 29 | yamlFile, err := ioutil.ReadFile("uuBot.yaml") 30 | if err != nil { 31 | fmt.Printf("打开配置文件错误...\n错误信息:%s", err) 32 | os.Exit(1) 33 | } 34 | if err = yaml.Unmarshal(yamlFile, c); err != nil { 35 | fmt.Printf("配置文件解析错误... \n错误信息:%s", err) 36 | os.Exit(1) 37 | } 38 | return c 39 | } 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 MiyaUU 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # v2board 签到机器人 2 | 3 | ``` 4 | 免责声明: 5 | 此库仅本人个人学习开发并维护, 不保证任何可用性。 6 | 有问题 提issue 7 | ( 悠悠的 baby..🌹 Try it!!! ) 8 | 9 | 喜欢🥰 就用你的小jiojio 点一个 ⭐️ Star ! thank you. -> 10 | ``` 11 | 12 | - [写代码很容易,写成一坨~😶‍🌫️.. 能用即可](https://github.com/trekhleb/state-of-the-art-shitcode) 13 | - 如果并不合您,请自行用❤️发电! 14 | 15 | ### UU说~ 16 | ``` 17 | 只能私信使用,不要拉到群里 18 | 可独立部署 另外申请一个bot即可,不与官方设置BOT冲突,可以两个一起用。不影响面板升级 19 | 20 | 其他功能 emmm 🧚🏻‍不嫌弃jiu 后续再更新... 21 | 22 | 这是我第一次用 go 不会写,大哥哥大姐姐🥱 不要喷wo, y~ 23 | ``` 24 | # 25 | 26 |
27 | 展开查看预览 28 | 29 | ![](uuBot.png) 30 |
31 | 32 | ## 如何使用它? 33 | 34 | ### 使用二进制文件部署(无需修改内容) 35 | 36 | ```shell 37 | # 下载 38 | 将版本压缩包clone 到你的服务器 39 | 40 | # 修改配置文件 41 | 修改 uuBot.yaml 配置 42 | 43 | # 机器人配置 44 | bot: 45 | name: "MiyaUU Bot" # 机器人名称,回复信息时使用 46 | token: "5036:AAEhtXJJW" # 机器人Token @BotFather 申请 47 | byte: 1024 # 签到可获取的最大值流量,不能奸商模式🔨 单位是MB 1024 为 最多1GB 48 | 49 | # 数据库配置 50 | database: 51 | host: "localhost" # 数据库地址 本地 或 ip 52 | port: 3306 # 数据库端口 53 | name: "v2board" # 数据库名称 54 | username: "root" # 数据库用户名 55 | password: "123123123" # 数据库密码 56 | ``` 57 | 58 | ### 运行 59 | 60 | ```shell 61 | 守护进程运行即可 62 | 由于时间关系 凌晨2点了 编程了夜猫子🥶. 先不写很多了,就看大家最最常用 PM2做示例 63 | 尽可能使用与面板同一台服务器部署,可以降低bot响应时间. 64 | 65 | # 安装pm2 (应该大部分人能看到这的都会安装了 66 | npm install pm2 -g 67 | 68 | # 启动 biu~ 69 | 二进制文件 uuBot 于 uuBot.yaml 要在同一个目录 70 | cd -> 工作目录 pm2 start uuBot 71 | 72 | 启动成功后 pm2 进程会多一个 uuBot 73 | 74 | supervisor 或者 docker 会用的应该也不用看教程了... 75 | 76 | ``` -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= 4 | github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 5 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 6 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 7 | github.com/jinzhu/now v1.1.3 h1:PlHq1bSCSZL9K0wUhbm2pGLoTWs2GwVhsP6emvGV/ZI= 8 | github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 9 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 10 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 11 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 12 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 13 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 14 | github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= 15 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 16 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 17 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 18 | gopkg.in/tucnak/telebot.v2 v2.5.0 h1:i+NynLo443Vp+Zn3Gv9JBjh3Z/PaiKAQwcnhNI7y6Po= 19 | gopkg.in/tucnak/telebot.v2 v2.5.0/go.mod h1:BgaIIx50PSRS9pG59JH+geT82cfvoJU/IaI5TJdN3v8= 20 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 21 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 22 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 23 | gorm.io/driver/mysql v1.2.2 h1:2qoqhOun1maoJOfLtnzJwq+bZlHkEF34rGntgySqp48= 24 | gorm.io/driver/mysql v1.2.2/go.mod h1:qsiz+XcAyMrS6QY+X3M9R6b/lKM1imKmcuK9kac5LTo= 25 | gorm.io/gorm v1.22.4 h1:8aPcyEJhY0MAt8aY6Dc524Pn+pO29K+ydu+e/cXSpQM= 26 | gorm.io/gorm v1.22.4/go.mod h1:1aeVC+pe9ZmvKZban/gW4QPra7PRoTEssyc922qCAkk= 27 | -------------------------------------------------------------------------------- /service/db.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "fmt" 5 | "gorm.io/driver/mysql" 6 | "gorm.io/gorm" 7 | "gorm.io/gorm/schema" 8 | "math/rand" 9 | "os" 10 | "time" 11 | ) 12 | 13 | type User struct { 14 | Id uint 15 | TelegramId uint 16 | Email string 17 | Token string 18 | U int64 19 | D int64 20 | PlanId int64 21 | Balance int64 22 | TransferEnable int64 23 | CommissionBalance int64 24 | ExpiredAt int64 25 | CreatedAt int64 26 | } 27 | 28 | type Plan struct { 29 | Id uint 30 | Name string 31 | } 32 | 33 | type UUBot struct { 34 | Id uint `gorm:"primaryKey"` 35 | UserId uint `gorm:"unique"` 36 | TelegramId uint `gorm:"unique" ` 37 | CheckinTraffic int64 38 | CheckinAt int64 39 | NextAt int64 40 | } 41 | 42 | var DB *gorm.DB 43 | var c Conf 44 | 45 | func init() { 46 | c.GetConfig() 47 | } 48 | 49 | func InitDB() *gorm.DB { 50 | dsn := fmt.Sprintf("%s:%s@tcp(%s:%v)/%s?charset=utf8mb4&parseTime=True&loc=Local", c.Database.Username, c.Database.Password, c.Database.Host, c.Database.Port, c.Database.Name) 51 | db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{ 52 | NamingStrategy: schema.NamingStrategy{ 53 | TablePrefix: "v2_", 54 | SingularTable: true, 55 | }, 56 | }) 57 | if err != nil { 58 | fmt.Printf("连接数据库失败... \n错误信息: %v", err) 59 | os.Exit(1) 60 | } 61 | if err = db.AutoMigrate(&UUBot{}); err != nil { 62 | fmt.Printf("数据库导入失败... \n错误信息: %v", err) 63 | os.Exit(1) 64 | } 65 | sqlDB, _ := db.DB() 66 | sqlDB.SetMaxIdleConns(10) 67 | sqlDB.SetMaxOpenConns(100) 68 | sqlDB.SetConnMaxLifetime(10 * time.Second) 69 | 70 | DB = db 71 | return db 72 | } 73 | 74 | func QueryPlan(planId int) Plan { 75 | var plan Plan 76 | DB.Where("id = ?", planId).First(&plan) 77 | return plan 78 | } 79 | 80 | func QueryUser(tgId int64) User { 81 | var user User 82 | DB.Where("telegram_id = ?", tgId).First(&user) 83 | return user 84 | } 85 | 86 | func BindUser(token string, tgId int64) User { 87 | var user User 88 | DB.Where("token = ?", token[6:]).First(&user) 89 | if user.Id <= 0 { 90 | return user 91 | } 92 | if user.TelegramId <= 0 { 93 | DB.Model(&user).Update("telegram_id", tgId) 94 | } 95 | return user 96 | } 97 | 98 | func unbindUser(tgId int64) User { 99 | var user User 100 | DB.Where("telegram_id = ?", tgId).First(&user) 101 | if user.Id > 0 { 102 | DB.Model(&user).Update("telegram_id", nil) 103 | return user 104 | } 105 | return user 106 | } 107 | 108 | func CheckinTime(tgId int64) bool { 109 | var uu UUBot 110 | DB.Where("telegram_id = ?", tgId).First(&uu) 111 | if time.Now().Unix() < uu.NextAt { 112 | return false 113 | } 114 | return true 115 | } 116 | 117 | func checkinUser(tgId int64) UUBot { 118 | var user User 119 | var uu UUBot 120 | DB.Where("telegram_id = ?", tgId).First(&user) 121 | DB.Where("telegram_id = ?", tgId).First(&uu) 122 | 123 | r := rand.New(rand.NewSource(time.Now().Unix())) 124 | b := r.Int63n(c.Bot.Byte) 125 | CheckIns := b * 1024 * 1024 126 | T := user.TransferEnable + CheckIns 127 | 128 | if uu.Id <= 0 { 129 | newUU := UUBot{ 130 | UserId: user.Id, 131 | TelegramId: user.TelegramId, 132 | CheckinAt: time.Now().Unix(), 133 | NextAt: time.Now().Unix() + 86400, 134 | CheckinTraffic: 0, 135 | } 136 | DB.Create(&newUU) 137 | } 138 | 139 | DB.Model(&uu).Updates(UUBot{ 140 | CheckinAt: time.Now().Unix(), 141 | NextAt: time.Now().Unix() + 86400, 142 | CheckinTraffic: CheckIns, 143 | }) 144 | DB.Model(&user).Update("transfer_enable", T) 145 | 146 | return uu 147 | } 148 | -------------------------------------------------------------------------------- /service/bot.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "fmt" 5 | tb "gopkg.in/tucnak/telebot.v2" 6 | "os" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | var Bot *tb.Bot 12 | 13 | func Start() { 14 | var err error 15 | Bot, err = tb.NewBot(tb.Settings{ 16 | URL: "https://api.telegram.org", 17 | Token: c.Bot.Token, 18 | Poller: &tb.LongPoller{Timeout: 10 * time.Second}, 19 | }) 20 | if err != nil { 21 | fmt.Printf("Bot 启动失败啦...... \n当前Token [ %s ] \n错误信息: %s", c.Bot.Token, err) 22 | os.Exit(1) 23 | } 24 | 25 | setHandle() 26 | Bot.Start() 27 | } 28 | 29 | func setHandle() { 30 | Bot.Handle("/start", startCmdCtr) 31 | Bot.Handle("/help", startCmdCtr) 32 | Bot.Handle("/checkin", checkinCmdCtr) 33 | Bot.Handle("/account", accountCmdCtr) 34 | Bot.Handle("/bind", bindCmdCtr) 35 | Bot.Handle("/unbind", unbindCmdCtr) 36 | } 37 | 38 | func startCmdCtr(m *tb.Message) { 39 | menu := &tb.ReplyMarkup{ResizeReplyKeyboard: true} 40 | CheckinBtn := menu.Text("🌈每日签到") 41 | AccountBtn := menu.Text("🧚🏻‍账户信息") 42 | BindBtn := menu.Text("💍绑定账户") 43 | UnbindBtn := menu.Text("🪖解绑账户") 44 | 45 | menu.Reply( 46 | menu.Row(CheckinBtn, AccountBtn), 47 | menu.Row(BindBtn, UnbindBtn), 48 | ) 49 | 50 | Bot.Handle(&CheckinBtn, checkinCmdCtr) 51 | Bot.Handle(&AccountBtn, accountCmdCtr) 52 | Bot.Handle(&BindBtn, bindCmdCtr) 53 | Bot.Handle(&UnbindBtn, unbindCmdCtr) 54 | 55 | msg := fmt.Sprintf("%s机器人🤖️\n为你提供以下服务:\n\n每日签到 /checkin\n账户信息 /account\n绑定账户 /bind\n解绑账户 /unbind", c.Bot.Name) 56 | _, _ = Bot.Send(m.Chat, msg, menu) 57 | } 58 | 59 | func checkinCmdCtr(m *tb.Message) { 60 | user := QueryUser(m.Chat.ID) 61 | if user.Id <= 0 { 62 | msg := "⛔️当前未绑定账户\n请发送 /bind <订阅地址> 绑定账户\n\n#示例\n/bind https://域名/api/v1/client/subscribe?token=c09a65fd29cb8453926642c0db2e74c0" 63 | _, _ = Bot.Send(m.Sender, msg) 64 | return 65 | } 66 | if user.PlanId <= 0 { 67 | msg := "⛔当前暂无订阅计划,请购买后才能签到赚取流量😯..." 68 | _, _ = Bot.Send(m.Sender, msg) 69 | return 70 | } 71 | 72 | cc := CheckinTime(m.Chat.ID) 73 | if cc == false { 74 | msg := fmt.Sprintf("🥳今天已经签到过啦...") 75 | _, _ = Bot.Send(m.Sender, msg) 76 | return 77 | } 78 | 79 | uu := checkinUser(m.Chat.ID) 80 | 81 | msg := fmt.Sprintf("💍签到成功\n本次签到获得 %s 流量\n下次签到时间: %s", ByteSize(uu.CheckinTraffic), UnixToStr(uu.NextAt)) 82 | _, _ = Bot.Send(m.Sender, msg) 83 | } 84 | 85 | func accountCmdCtr(m *tb.Message) { 86 | user := QueryUser(m.Chat.ID) 87 | if user.Id <= 0 { 88 | msg := "⛔️当前未绑定账户\n请发送 /bind <订阅地址> 绑定账户\n\n#示例\n/bind https://域名/api/v1/client/subscribe?token=c09a65fd29cb8453926642c0db2e74c0" 89 | _, _ = Bot.Send(m.Sender, msg) 90 | return 91 | } 92 | p := QueryPlan(int(user.PlanId)) 93 | Email := user.Email 94 | CreatedAt := UnixToStr(user.CreatedAt) 95 | Balance := user.Balance / 100 96 | CommissionBalance := user.CommissionBalance / 100 97 | PlanName := p.Name 98 | ExpiredAt := UnixToStr(user.ExpiredAt) 99 | TransferEnable := ByteSize(user.TransferEnable) 100 | U := ByteSize(user.U) 101 | D := ByteSize(user.D) 102 | S := ByteSize(user.TransferEnable - (user.U + user.D)) 103 | if user.PlanId <= 0 { 104 | msg := fmt.Sprintf("🧚🏻账户信息概况:\n\n当前绑定账户: %s\n注册时间: %s\n账户余额: %d元\n佣金余额: %d元\n\n当前订阅: 当前暂无订阅计划", Email, CreatedAt, Balance, CommissionBalance) 105 | _, _ = Bot.Send(m.Sender, msg) 106 | return 107 | } 108 | 109 | msg := fmt.Sprintf("🧚🏻账户信息概况:\n\n当前绑定账户: %s\n注册时间: %s\n账户余额: %d元\n佣金余额: %d元\n\n当前订阅: %s\n到期时间: %s\n订阅流量: %s\n已用上行: %s\n已用下行: %s\n剩余可用: %s", Email, CreatedAt, Balance, CommissionBalance, PlanName, ExpiredAt, TransferEnable, U, D, S) 110 | _, _ = Bot.Send(m.Sender, msg) 111 | 112 | } 113 | 114 | func bindCmdCtr(m *tb.Message) { 115 | user := QueryUser(m.Chat.ID) 116 | if user.Id > 0 { 117 | _, _ = Bot.Send(m.Sender, fmt.Sprintf("⭐您当前绑定账户: %s\n若需要修改绑定,请先解绑当前账户!", user.Email)) 118 | return 119 | } 120 | 121 | format := strings.Index(m.Text, "token=") 122 | if format <= 0 { 123 | _, _ = Bot.Send(m.Sender, "⭐️️账户绑定格式: /bind <订阅地址>\n\n 发送示例:\n/bind https://域名/api/v1/client/subscribe?token=c09a65fd29cb8453926642c0db2e74c0") 124 | return 125 | } 126 | 127 | b := BindUser(m.Text[format:], m.Chat.ID) 128 | if b.Id <= 0 { 129 | _, _ = Bot.Send(m.Sender, "❌订阅无效,请前往官网复制最新订阅地址!") 130 | return 131 | } 132 | 133 | if b.TelegramId != uint(m.Chat.ID) { 134 | _, _ = Bot.Send(m.Sender, "❌账户绑定失败,请稍后再试") 135 | } 136 | _, _ = Bot.Send(m.Sender, fmt.Sprintf("💍账户绑定成功: %s", b.Email)) 137 | } 138 | 139 | func unbindCmdCtr(m *tb.Message) { 140 | user := unbindUser(m.Chat.ID) 141 | if user.Id <= 0 { 142 | _, _ = Bot.Send(m.Sender, "⛔️当前未绑定账户") 143 | return 144 | } 145 | if user.TelegramId > 0 { 146 | _, _ = Bot.Send(m.Sender, "❌账户解绑失败,请稍后再试...") 147 | return 148 | } 149 | _, _ = Bot.Send(m.Sender, "🪖账户解绑成功") 150 | } 151 | 152 | func UnixToStr(unix int64) string { 153 | u := time.Unix(unix, 0).Format("2006-01-02 15:04:05") 154 | return u 155 | } 156 | 157 | func ByteSize(size int64) string { 158 | if size < 1024 { 159 | return fmt.Sprintf("%.2fB", float64(size)/float64(1)) 160 | } else if size < (1024 * 1024) { 161 | return fmt.Sprintf("%.2fKB", float64(size)/float64(1024)) 162 | } else if size < (1024 * 1024 * 1024) { 163 | return fmt.Sprintf("%.2fMB", float64(size)/float64(1024*1024)) 164 | } else if size < (1024 * 1024 * 1024 * 1024) { 165 | return fmt.Sprintf("%.2fGB", float64(size)/float64(1024*1024*1024)) 166 | } else { 167 | return fmt.Sprintf("%.2fTB", float64(size)/float64(1024*1024*1024*1024)) 168 | } 169 | } 170 | --------------------------------------------------------------------------------