style: rename controllers to login, cancel internal/pkg
This commit is contained in:
@@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config/keys"
|
"github.com/Mmx233/BitSrunLoginGo/internal/config/keys"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/controllers"
|
"github.com/Mmx233/BitSrunLoginGo/internal/login"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -14,10 +14,10 @@ func main() {
|
|||||||
|
|
||||||
if config.Settings.Guardian.Enable {
|
if config.Settings.Guardian.Enable {
|
||||||
//进入守护模式
|
//进入守护模式
|
||||||
controllers.Guardian(logger.WithField(keys.LogComponent, "guard"))
|
login.Guardian(logger.WithField(keys.LogComponent, "guard"))
|
||||||
} else {
|
} else {
|
||||||
//执行单次流程
|
//执行单次流程
|
||||||
_ = controllers.Login(controllers.LoginConf{
|
_ = login.Login(login.Conf{
|
||||||
Logger: logger.WithField(keys.LogComponent, "login"),
|
Logger: logger.WithField(keys.LogComponent, "login"),
|
||||||
IsOnlineDetectLogDebugLevel: false,
|
IsOnlineDetectLogDebugLevel: false,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/aliyun"
|
"github.com/Mmx233/BitSrunLoginGo/internal/dns/aliyun"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/cloudflare"
|
"github.com/Mmx233/BitSrunLoginGo/internal/dns/cloudflare"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/dnspod"
|
"github.com/Mmx233/BitSrunLoginGo/internal/dns/dnspod"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
dnsUtil "github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/util"
|
"github.com/Mmx233/BitSrunLoginGo/internal/dns/util"
|
||||||
"github.com/Mmx233/tool"
|
"github.com/Mmx233/tool"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -3,9 +3,9 @@ package dns
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/aliyun"
|
"github.com/Mmx233/BitSrunLoginGo/internal/dns/aliyun"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/cloudflare"
|
"github.com/Mmx233/BitSrunLoginGo/internal/dns/cloudflare"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/dnspod"
|
"github.com/Mmx233/BitSrunLoginGo/internal/dns/dnspod"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package dnspod
|
package dnspod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
dnsUtil "github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns/util"
|
"github.com/Mmx233/BitSrunLoginGo/internal/dns/util"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions"
|
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package controllers
|
package login
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
func Guardian(logger log.FieldLogger) {
|
func Guardian(logger log.FieldLogger) {
|
||||||
GuardianDuration := time.Duration(config.Settings.Guardian.Duration) * time.Second
|
GuardianDuration := time.Duration(config.Settings.Guardian.Duration) * time.Second
|
||||||
for {
|
for {
|
||||||
_ = Login(LoginConf{
|
_ = Login(Conf{
|
||||||
Logger: logger.WithField(keys.LogComponent, "login"),
|
Logger: logger.WithField(keys.LogComponent, "login"),
|
||||||
IsOnlineDetectLogDebugLevel: true,
|
IsOnlineDetectLogDebugLevel: true,
|
||||||
})
|
})
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package controllers
|
package login
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
"github.com/Mmx233/BitSrunLoginGo/internal/config"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config/flags"
|
"github.com/Mmx233/BitSrunLoginGo/internal/config/flags"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/config/keys"
|
"github.com/Mmx233/BitSrunLoginGo/internal/config/keys"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/dns"
|
dns2 "github.com/Mmx233/BitSrunLoginGo/internal/dns"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/internal/pkg/http_client"
|
"github.com/Mmx233/BitSrunLoginGo/internal/http_client"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/pkg/srun"
|
"github.com/Mmx233/BitSrunLoginGo/pkg/srun"
|
||||||
"github.com/Mmx233/BitSrunLoginGo/tools"
|
"github.com/Mmx233/BitSrunLoginGo/tools"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@@ -20,16 +20,16 @@ import (
|
|||||||
var ipLast string
|
var ipLast string
|
||||||
var debugTip sync.Once
|
var debugTip sync.Once
|
||||||
|
|
||||||
type LoginConf struct {
|
type Conf struct {
|
||||||
Logger log.FieldLogger
|
Logger log.FieldLogger
|
||||||
IsOnlineDetectLogDebugLevel bool
|
IsOnlineDetectLogDebugLevel bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func Login(conf LoginConf) error {
|
func Login(conf Conf) error {
|
||||||
logger := conf.Logger
|
logger := conf.Logger
|
||||||
if config.Settings.Basic.Interfaces == "" { //单网卡
|
if config.Settings.Basic.Interfaces == "" { //单网卡
|
||||||
err := LoginSingle(LoginSingleConf{
|
err := Single(SingleConf{
|
||||||
LoginConf: conf,
|
Conf: conf,
|
||||||
Eth: nil,
|
Eth: nil,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -42,12 +42,12 @@ func Login(conf LoginConf) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
} else { //多网卡
|
} else { //多网卡
|
||||||
return LoginInterfaces(conf)
|
return Interfaces(conf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ddns(logger log.FieldLogger, ip string, httpClient *http.Client) error {
|
func ddns(logger log.FieldLogger, ip string, httpClient *http.Client) error {
|
||||||
return dns.Run(&dns.Config{
|
return dns2.Run(&dns2.Config{
|
||||||
Logger: logger.WithField(keys.LogLoginModule, "ddns"),
|
Logger: logger.WithField(keys.LogLoginModule, "ddns"),
|
||||||
Provider: config.Settings.DDNS.Provider,
|
Provider: config.Settings.DDNS.Provider,
|
||||||
IP: ip,
|
IP: ip,
|
||||||
@@ -58,7 +58,7 @@ func ddns(logger log.FieldLogger, ip string, httpClient *http.Client) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoginInterfaces(conf LoginConf) error {
|
func Interfaces(conf Conf) error {
|
||||||
logger := conf.Logger
|
logger := conf.Logger
|
||||||
interfaces, err := tools.GetInterfaceAddr(logger, config.Settings.Basic.Interfaces)
|
interfaces, err := tools.GetInterfaceAddr(logger, config.Settings.Basic.Interfaces)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -68,8 +68,8 @@ func LoginInterfaces(conf LoginConf) error {
|
|||||||
var errCount int
|
var errCount int
|
||||||
for i, eth := range interfaces {
|
for i, eth := range interfaces {
|
||||||
logger.Infoln("使用网卡: ", eth.Name)
|
logger.Infoln("使用网卡: ", eth.Name)
|
||||||
if err := LoginSingle(LoginSingleConf{
|
if err := Single(SingleConf{
|
||||||
LoginConf: conf,
|
Conf: conf,
|
||||||
Eth: ð,
|
Eth: ð,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
logger.Errorf("网卡 %s 登录出错: %v", eth.Name, err)
|
logger.Errorf("网卡 %s 登录出错: %v", eth.Name, err)
|
||||||
@@ -85,12 +85,12 @@ func LoginInterfaces(conf LoginConf) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginSingleConf struct {
|
type SingleConf struct {
|
||||||
LoginConf
|
Conf
|
||||||
Eth *tools.Eth
|
Eth *tools.Eth
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoginSingle(conf LoginSingleConf) error {
|
func Single(conf SingleConf) error {
|
||||||
if config.Settings.Backoff.Enable {
|
if config.Settings.Backoff.Enable {
|
||||||
return backoff.NewInstance(func(ctx context.Context) error {
|
return backoff.NewInstance(func(ctx context.Context) error {
|
||||||
return doLogin(conf)
|
return doLogin(conf)
|
||||||
@@ -100,7 +100,7 @@ func LoginSingle(conf LoginSingleConf) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doLogin(conf LoginSingleConf) error {
|
func doLogin(conf SingleConf) error {
|
||||||
logger := conf.Logger
|
logger := conf.Logger
|
||||||
|
|
||||||
// 登录配置初始化
|
// 登录配置初始化
|
||||||
Reference in New Issue
Block a user