Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
e1732a364fed committed Dec 12, 2022
1 parent 03fc52c commit ca888d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
19 changes: 16 additions & 3 deletions cmd/verysimple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func mainFunc() (result int) {
ce.Write(zap.Any("flags", utils.GivenFlagKVs()))
}

if loadConfigErr != nil && !defaultMachine.IsFlexible(interactive_mode, gui_mode) {
if loadConfigErr != nil && !IsFlexible(defaultMachine) {

if ce := utils.CanLogErr(willExitStr); ce != nil {
ce.Write(zap.Error(loadConfigErr))
Expand Down Expand Up @@ -358,7 +358,7 @@ func mainFunc() (result int) {
}

//没可用的listen/dial,而且还无法动态更改配置
if defaultMachine.NoFuture(interactive_mode, gui_mode) {
if NoFuture(defaultMachine) {
utils.Error(willExitStr)
return -1
}
Expand Down Expand Up @@ -397,7 +397,7 @@ func mainFunc() (result int) {
}
}

if defaultMachine.NothingRunning(interactive_mode, gui_mode) {
if NothingRunning(defaultMachine) {
utils.Warn(willExitStr)
return
}
Expand All @@ -413,3 +413,16 @@ func mainFunc() (result int) {
}
return
}

// 是否可以在运行时动态修改配置。如果没有开启 apiServer 开关 也没有 动态修改配置的功能,则当前模式不灵活,无法动态修改
func IsFlexible(m *machine.M) bool {
return interactive_mode || gui_mode || m.EnableApiServer
}

func NoFuture(m *machine.M) bool {
return !m.HasProxyRunning() && !IsFlexible(m)
}

func NothingRunning(m *machine.M) bool {
return !m.HasProxyRunning() && !(interactive_mode || gui_mode || m.ApiServerRunning)
}
13 changes: 0 additions & 13 deletions machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,6 @@ func (m *M) HasProxyRunning() bool {
return len(m.ListenCloserList) > 0
}

// 是否可以在运行时动态修改配置。如果没有开启 apiServer 开关 也没有 动态修改配置的功能,则当前模式不灵活,无法动态修改
func (m *M) IsFlexible(interactive_mode, Gui_mode bool) bool {
return interactive_mode || m.EnableApiServer || Gui_mode
}

func (m *M) NoFuture(interactive_mode, Gui_mode bool) bool {
return !m.HasProxyRunning() && !m.IsFlexible(interactive_mode, Gui_mode)
}

func (m *M) NothingRunning(interactive_mode, Gui_mode bool) bool {
return !m.HasProxyRunning() && !(interactive_mode || m.ApiServerRunning || Gui_mode)
}

func (m *M) PrintAllState(w io.Writer) {
if w == nil {
w = os.Stdout
Expand Down

0 comments on commit ca888d9

Please sign in to comment.