tomcatfixgo/main.go

68 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"errors"
"fmt"
"os"
"strings"
log "github.com/sirupsen/logrus"
)
func main() {
// 初始化日志信息
log.SetFormatter(&log.TextFormatter{})
file, err := os.Create("tomcatfix.log")
defer file.Close()
if err != nil {
fmt.Println("日志文件创建失败")
return
}
log.SetOutput(file)
log.SetLevel(log.WarnLevel)
readServerXMl()
}
/*
读取配置
@author lroyia
@since 2022年1月6日 15:31:41
*/
func readServerXMl(){
home, err := getHome()
if err != nil{
log.Debug(err.Error())
os.Exit(0)
}
}
/**
获取CATALINA_HOME
@author lroyia
@since 2022年1月6日 15:30:32
*/
func getHome() (string, error){
home:= ""
// 1、从命令行参数中获取
for _, each := range os.Args {
if(strings.Index(each, "-H=") == 0){
home = strings.Split(each, "=")[1]
return home, nil
}
}
// 2、判断是否为当前目录如果是则获取当前目录
_, err := os.Stat("webapps")
defer os.Stat("..")
if err != nil && os.IsExist(err) {
return home, nil
}
// 3、获取环境变量中的CATALINA_HOME
home = os.Getenv("CATALINA_HOME")
if home == "" {
return "", errors.New("没有找到CATALINA_HOME")
}
return home, _
}