Change logs and formatting
This commit is contained in:
@@ -9,23 +9,24 @@ import (
|
||||
)
|
||||
|
||||
type CommandClientHandler struct {
|
||||
name string
|
||||
port int64
|
||||
}
|
||||
|
||||
func (cch *CommandClientHandler) Connected() {
|
||||
fmt.Println("connected")
|
||||
fmt.Printf("[%s] CONNECTED\n", cch.name)
|
||||
}
|
||||
|
||||
func (cch *CommandClientHandler) Disconnected(message string) {
|
||||
fmt.Printf("disconnected: %s\n", message)
|
||||
fmt.Printf("[%s] DISCONNECTED: %s\n", cch.name, message)
|
||||
}
|
||||
|
||||
func (cch *CommandClientHandler) ClearLog() {
|
||||
fmt.Println("clear log")
|
||||
fmt.Printf("[%s] clear log\n", cch.name)
|
||||
}
|
||||
|
||||
func (cch *CommandClientHandler) WriteLog(message string) {
|
||||
fmt.Printf("new log: %s\n", message)
|
||||
fmt.Printf("[%s] log: %s\n", cch.name, message)
|
||||
}
|
||||
|
||||
func (cch *CommandClientHandler) WriteStatus(message *libbox.StatusMessage) {
|
||||
@@ -77,9 +78,12 @@ func (cch *CommandClientHandler) WriteGroups(message libbox.OutboundGroupIterato
|
||||
}
|
||||
|
||||
func (cch *CommandClientHandler) InitializeClashMode(modeList libbox.StringIterator, currentMode string) {
|
||||
fmt.Printf("[%s] clash mode: %s\n", cch.name, currentMode)
|
||||
}
|
||||
|
||||
func (cch *CommandClientHandler) UpdateClashMode(newMode string) {}
|
||||
func (cch *CommandClientHandler) UpdateClashMode(newMode string) {
|
||||
fmt.Printf("[%s] update clash mode: %s\n", cch.name, newMode)
|
||||
}
|
||||
|
||||
type OutboundGroup struct {
|
||||
Tag string `json:"tag"`
|
||||
|
||||
@@ -3,30 +3,30 @@ package main
|
||||
import "github.com/sagernet/sing-box/experimental/libbox"
|
||||
|
||||
var (
|
||||
statusCommand *libbox.CommandClient
|
||||
groupCommand *libbox.CommandClient
|
||||
statusClient *libbox.CommandClient
|
||||
groupClient *libbox.CommandClient
|
||||
)
|
||||
|
||||
func StartCommand(command int32, port int64) error {
|
||||
switch command {
|
||||
case libbox.CommandStatus:
|
||||
statusCommand = libbox.NewCommandClient(
|
||||
&CommandClientHandler{port: port},
|
||||
statusClient = libbox.NewCommandClient(
|
||||
&CommandClientHandler{port: port, name: "status"},
|
||||
&libbox.CommandClientOptions{
|
||||
Command: libbox.CommandStatus,
|
||||
StatusInterval: 1000000000,
|
||||
},
|
||||
)
|
||||
return statusCommand.Connect()
|
||||
return statusClient.Connect()
|
||||
case libbox.CommandGroup:
|
||||
groupCommand = libbox.NewCommandClient(
|
||||
&CommandClientHandler{port: port},
|
||||
groupClient = libbox.NewCommandClient(
|
||||
&CommandClientHandler{port: port, name: "group"},
|
||||
&libbox.CommandClientOptions{
|
||||
Command: libbox.CommandGroup,
|
||||
StatusInterval: 1000000000,
|
||||
},
|
||||
)
|
||||
return groupCommand.Connect()
|
||||
return groupClient.Connect()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -34,12 +34,12 @@ func StartCommand(command int32, port int64) error {
|
||||
func StopCommand(command int32) error {
|
||||
switch command {
|
||||
case libbox.CommandStatus:
|
||||
err := statusCommand.Disconnect()
|
||||
statusCommand = nil
|
||||
err := statusClient.Disconnect()
|
||||
statusClient = nil
|
||||
return err
|
||||
case libbox.CommandGroup:
|
||||
err := groupCommand.Disconnect()
|
||||
groupCommand = nil
|
||||
err := groupClient.Disconnect()
|
||||
groupClient = nil
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user