72 Star 907 Fork 298

Kevin2li / PDF-Guru

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
trial.go 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
Kevin2li 提交于 2023-07-25 08:16 . update: 添加试用功能
package main
import (
"fmt"
"os"
"path/filepath"
"strconv"
"github.com/pkg/errors"
)
func (a *App) CheckTrialCount() (int, error) {
countPath := filepath.Join(logdir, "debug.log")
count := 0
if _, err := os.Stat(countPath); err == nil {
// file exists
countFile, err := os.OpenFile(countPath, os.O_RDONLY, 0666)
if err != nil {
err = errors.Wrap(err, "无法验证试用状态!")
return count, err
}
defer countFile.Close()
countBytes, err := os.ReadFile(countPath)
if err != nil {
err = errors.Wrap(err, "无法验证试用状态!")
return count, err
}
count, err = strconv.Atoi(string(countBytes))
if err != nil {
err = errors.Wrap(err, "无法验证试用状态!")
return count, err
}
countFile.Close()
countFile, err = os.OpenFile(countPath, os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
err = errors.Wrap(err, "无法验证试用状态!")
return count, err
}
defer countFile.Close()
countFile.WriteString(strconv.Itoa(count + 1))
return count + 1, nil
} else if os.IsNotExist(err) {
// file not exists
countFile, err := os.OpenFile(countPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
err = errors.Wrap(err, "无法验证试用状态!")
return count, err
}
defer countFile.Close()
countFile.WriteString("1")
return 1, nil
}
return count, fmt.Errorf("无法验证试用状态!")
}
Go
1
https://gitee.com/Kevin234/PDF-Guru.git
git@gitee.com:Kevin234/PDF-Guru.git
Kevin234
PDF-Guru
PDF-Guru
main

搜索帮助