docs: 增加注释

This commit is contained in:
Mmx
2021-12-02 13:46:01 +08:00
parent 680130aaef
commit 07d66ced1e
6 changed files with 18 additions and 2 deletions

View File

@@ -14,6 +14,7 @@ type daemon struct {
Path string
}
// Daemon 后台模式控制包
var Daemon = daemon{
Mark: fmt.Sprint(time.Now().UnixNano()),
Path: global.Config.Settings.Daemon.Path,
@@ -25,10 +26,12 @@ func init() {
}
}
// MarkDaemon 写入后台标记文件
func (a *daemon) MarkDaemon() error {
return tool.File.Write(a.Path, []byte(a.Mark))
}
// CheckDaemon 检查后台标记文件
func (a *daemon) CheckDaemon() bool {
if data, err := tool.File.Read(a.Path); err != nil {
return false
@@ -37,6 +40,7 @@ func (a *daemon) CheckDaemon() bool {
}
}
// DaemonChan 后台标记文件监听
func (a *daemon) DaemonChan() bool {
f, err := fsnotify.NewWatcher()
if err != nil {

View File

@@ -8,6 +8,7 @@ import (
"time"
)
// Guardian 守护模式逻辑
func Guardian(output bool) {
util.Log.OutPut = output
@@ -44,6 +45,7 @@ func Guardian(output bool) {
}
}
// EnterGuardian 守护模式入口控制是否进入daemon
func EnterGuardian() {
util.Log.OutPut = true
util.Log.Println("[Guardian mode]")

View File

@@ -6,6 +6,7 @@ import (
"github.com/Mmx233/BitSrunLoginGo/v1/transfer"
)
// Login 登录逻辑
func Login(output bool, skipCheck bool) error {
return BitSrun.Login(&srunTransfer.Login{
Demo: global.Config.Settings.DemoMode,

View File

@@ -5,8 +5,11 @@ import (
)
var Flags struct {
//配置文件路径
Path string
//daemon模式内置标记
RunningDaemon bool
//强制daemon
Daemon bool
}

View File

@@ -9,6 +9,7 @@ type checker struct{}
var Checker checker
// NetOk 网络状况检查
func (checker) NetOk(timeout uint) bool {
h, _, e := tool.HTTP.GetBytes(&tool.GetRequest{
Url: "https://www.baidu.com/",

View File

@@ -21,6 +21,7 @@ func Search(reg string, content string) (string, error) {
}
}
// GetIp 从响应获取本机分配到的IP
func GetIp(body string) (string, error) {
//判断原正则是否有匹配,如果无就使用新正则尝试
if ip, e := Search("id=\"user_ip\" value=\"(.*?)\"", body); e == nil {
@@ -29,20 +30,24 @@ func GetIp(body string) (string, error) {
return Search("ip : \"(.*?)\"", body)
}
// GetToken 从响应获取token
func GetToken(body string) (string, error) {
return Search("\"challenge\":\"(.*?)\"", body)
}
// GetResult 从响应获取登录结果
func GetResult(body string) (string, error) {
return Search("\"error\":\"(.+?)\"", body)
}
// Md5 编码
func Md5(content string) string {
w := md5.New()
_, _ = io.WriteString(w, content)
return fmt.Sprintf("%x", w.Sum(nil))
}
// Sha1 编码
func Sha1(content string) string {
h := sha1.New()
h.Write([]byte(content))