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