You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package main
import (
"dsSso/Utils/ConfigUtil"
"flag"
"fmt"
"io/ioutil"
"strings"
)
func main ( ) {
// 行为
var action string
// StringVar用指定的名称、控制台参数项目、默认值、使用信息注册一个string类型flag, 并将flag的值保存到p指向的变量
flag . StringVar ( & action , "action" , "localhost" , "行为,默认为本机" )
// 从arguments中解析注册的flag。必须在所有flag都注册好而未访问其值时执行。未注册却使用flag -help时, 会返回ErrHelp。
flag . Parse ( )
//找到main.go中
path := "./main.go"
buf , err := ioutil . ReadFile ( path )
if err != nil {
fmt . Println ( "发生了严重错误!" )
}
content := string ( buf )
a := "@host 127.0.0.1:" + ConfigUtil . ServerPort
b := "@host " + ConfigUtil . DistributeIp + ":" + ConfigUtil . ServerPort
//转为远程服务器IP
if action == "remote" {
//2、替换为配置文件中的发布主机IP
newContent := strings . Replace ( content , a , b , - 1 )
//重新写入
ioutil . WriteFile ( path , [ ] byte ( newContent ) , 0644 )
fmt . Println ( "恭喜, 替换swagger的发布ip成功替换为远程主机IP! " )
} else if action == "localhost" { //转为本机IP
//替换
//2、替换为配置文件中的本地IP
newContent := strings . Replace ( content , b , a , - 1 )
//重新写入
ioutil . WriteFile ( path , [ ] byte ( newContent ) , 0644 )
fmt . Println ( "恭喜, 替换swagger的发布ip成功替换为本机IP! " )
} else {
fmt . Println ( "输入的 action参数不正确, 只能是localhost或者 remote !" )
}
}