-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add graceful shutdown and add macos dns for tun mode
- Loading branch information
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package terminal_func | ||
|
||
import ( | ||
"context" | ||
"github.com/mythologyli/zju-connect/log" | ||
) | ||
|
||
type TerminalFunc func(ctx context.Context) error | ||
type TerminalItem struct { | ||
f TerminalFunc | ||
name string | ||
} | ||
|
||
var terminalFuncList []TerminalItem | ||
|
||
func RegisterTerminalFunc(execName string, fun TerminalFunc) { | ||
terminalFuncList = append(terminalFuncList, TerminalItem{ | ||
f: fun, | ||
name: execName, | ||
}) | ||
log.Println("Register func on terminal:", execName) | ||
} | ||
|
||
func ExecTerminalFunc(ctx context.Context) []error { | ||
var errList []error | ||
for _, item := range terminalFuncList { | ||
log.Println("Exec func on terminal:", item.name) | ||
if err := item.f(ctx); err != nil { | ||
errList = append(errList, err) | ||
log.Println("Exec func on terminal ", item.name, "failed:", err) | ||
} else { | ||
log.Println("Exec func on terminal ", item.name, "success") | ||
} | ||
} | ||
return errList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters