Skip to content

Commit

Permalink
style: 修改OOP代码
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Nov 8, 2023
1 parent 9576773 commit 132e802
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 45 deletions.
34 changes: 23 additions & 11 deletions client/cmd/fork/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package fork

import (
"os"
"os/exec"

"github.com/opentdp/go-helper/logman"

"github.com/opentdp/blackbox/client/cmd/args"
"github.com/opentdp/blackbox/client/module/capi"
"github.com/opentdp/blackbox/client/module/glue"
)

func Checkin() {
glueApps()
if len(os.Args) > 1 {
glue.Start(os.Args[1])
}

if err := capi.Join(); err != nil {
logman.Fatal("Fetch config failed", "msg", err)
Expand All @@ -20,16 +24,24 @@ func Checkin() {
go forkPrometheusBlackbox()
}

func glueApps() {
if len(os.Args) < 2 {
return
}
if os.Args[1] == "--config" {
glue.FrpClient()
os.Exit(0)
func forkFrpClient() {
etc := args.FrpClientConfig
cmd := exec.Command(args.ExecutablePath, "--config", etc)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr

if err := cmd.Start(); err != nil {
logman.Fatal("Start frpc failed", "msg", err)
}
if os.Args[1] == "--config.file" {
glue.PrometheusBlackbox()
os.Exit(0)
cmd.Wait()
}

func forkPrometheusBlackbox() {
etc := args.PrometheusBlackboxConfig
cmd := exec.Command(args.ExecutablePath, "--config.file", etc)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr

if err := cmd.Start(); err != nil {
logman.Fatal("Start prometheus blackbox failed", "msg", err)
}
cmd.Wait()
}
32 changes: 0 additions & 32 deletions client/cmd/fork/rewrite.go

This file was deleted.

17 changes: 15 additions & 2 deletions client/module/glue/execute.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package glue

import (
"os"

"github.com/opentdp/go-helper/logman"

"github.com/opentdp/blackbox/client/module/glue/frp_client"
"github.com/opentdp/blackbox/client/module/glue/prometheus_blackbox"
)

func FrpClient() {
func Start(arg1 string) {
switch arg1 {
case "--config":
frpClient()
case "--config.file":
prometheusBlackbox()
}
}

func frpClient() {
frp_client.Execute()
logman.Info("frp client exited")
os.Exit(0)
}

func PrometheusBlackbox() {
func prometheusBlackbox() {
prometheus_blackbox.Execute()
logman.Info("prometheus blackbox exited")
os.Exit(0)
}

0 comments on commit 132e802

Please sign in to comment.