https 节点检测

This commit is contained in:
2025-01-08 14:41:07 +08:00
commit fee0c7d845
15 changed files with 512 additions and 0 deletions

21
common/common.go Normal file
View File

@@ -0,0 +1,21 @@
package common
const (
AppEnv = "dev"
EnvConfig = "config.json"
)
type Config struct {
Debug bool `mapstructure:"debug" json:"debug" yaml:"debug"`
TargetURL string `mapstructure:"target_url" json:"target_url" yaml:"target_url"`
Nodes []Node `mapstructure:"nodes" json:"nodes" yaml:"nodes"`
}
type Node struct {
Protocol string `mapstructure:"protocol" yaml:"protocol" json:"protocol"`
Username string `mapstructure:"username" yaml:"username" json:"username"`
Password string `mapstructure:"password" yaml:"password" json:"password"`
Addr string `mapstructure:"addr" yaml:"addr" json:"addr"`
Port int `mapstructure:"port" yaml:"port" json:"port"`
Ports []int `mapstructure:"ports" yaml:"ports" json:"ports"`
}

54
common/viper/viper.go Normal file
View File

@@ -0,0 +1,54 @@
package viper
import (
"flag"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"httppp/common"
"httppp/global"
"os"
)
func InitViper(path ...string) {
var confPath string
if len(path) == 0 {
flag.StringVar(&confPath, "c", "", "choose config file.")
flag.Parse()
if confPath == "" {
if AppEnv := os.Getenv(common.AppEnv); AppEnv == "" {
confPath = common.EnvConfig
} else {
confPath = AppEnv
}
} else {
}
} else {
confPath = path[0]
}
v := viper.New()
v.SetConfigFile(confPath)
v.SetConfigType("json")
err := v.ReadInConfig()
if err != nil {
fmt.Printf("[-]读取配置文件错误: %s \n", err)
os.Exit(0)
}
v.WatchConfig()
v.OnConfigChange(func(e fsnotify.Event) {
if err = v.Unmarshal(&global.Conf); err != nil {
fmt.Printf("[-]重新解析配置文件失败: %s \n", err)
os.Exit(0)
}
fmt.Println("[+]重新加载配置文件完成")
})
if err = v.Unmarshal(&global.Conf); err != nil {
fmt.Printf("[-]解析配置文件失败: %s \n", err)
os.Exit(0)
}
fmt.Println("[+]加载配置文件完成")
//dump.P(global.AppConf)
}