2022-11-20 14:11:47 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"regexp"
|
2023-02-03 04:43:37 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2022-11-20 14:11:47 +00:00
|
|
|
)
|
|
|
|
|
2023-01-13 11:32:50 +00:00
|
|
|
var VERSION = "v1.0.0"
|
2023-01-12 03:21:57 +00:00
|
|
|
|
2023-01-13 11:32:50 +00:00
|
|
|
func GetKey(key, defaultValue string) string {
|
2022-11-20 14:11:47 +00:00
|
|
|
file, err := os.ReadFile(path.Join("data", "config", "config.sh"))
|
|
|
|
if err != nil {
|
2023-01-13 11:32:50 +00:00
|
|
|
return defaultValue
|
2022-11-20 14:11:47 +00:00
|
|
|
}
|
|
|
|
compile := regexp.MustCompile(key + `="(.*?)"`)
|
|
|
|
if !compile.Match(file) {
|
2023-01-13 11:32:50 +00:00
|
|
|
return defaultValue
|
2022-11-20 14:11:47 +00:00
|
|
|
}
|
|
|
|
datas := compile.FindAllStringSubmatch(string(file), 1)
|
|
|
|
return datas[0][1]
|
|
|
|
}
|
2023-01-12 03:21:57 +00:00
|
|
|
|
|
|
|
func GetVersion() string {
|
2023-09-04 06:02:25 +00:00
|
|
|
return strings.TrimPrefix(VERSION, "v")
|
2023-01-12 03:21:57 +00:00
|
|
|
}
|
2023-02-03 04:43:37 +00:00
|
|
|
|
|
|
|
var address string
|
|
|
|
|
|
|
|
func SetAddress(add string) {
|
|
|
|
address = add
|
|
|
|
}
|
|
|
|
|
|
|
|
func ListenPort() int {
|
|
|
|
split := strings.Split(address, ":")
|
|
|
|
port, _ := strconv.Atoi(split[1])
|
|
|
|
return port
|
|
|
|
}
|