From 9be737ae56d90e086f251b5410fe2dbc47a29adc Mon Sep 17 00:00:00 2001 From: NanamiAdmin Date: Mon, 2 Mar 2026 13:20:38 +0800 Subject: [PATCH] feat: add FrpcProxyInfo struct and logging enhancements - Introduce FrpcProxyInfo struct to support proxy configuration - Add logging statements to instance creation, deletion, and modification handlers - Implement addFrpcProxy function for generating proxy configuration --- frpc.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/frpc.go b/frpc.go index 433cd8b..c6caefb 100644 --- a/frpc.go +++ b/frpc.go @@ -25,6 +25,14 @@ type InstanceInfo struct { Additional map[string]interface{} `json:"additionalProperties"` } +type FrpcProxyInfo struct { + Name string `json:"name"` + Type string `json:"type"` + LocalIP string `json:"local_ip"` + LocalPort string `json:"local_port"` + RemotePort string `json:"remote_port"` +} + type CreateInstanceRequest struct { InstanceInfo InstanceInfo `json:"instanceInfo"` BootAtStart bool `json:"bootAtStart"` @@ -195,6 +203,7 @@ func CreateInstanceHandler(w http.ResponseWriter, r *http.Request) { "configPath": configPath, "bootAtStart": req.BootAtStart, }) + postLog.Info(fmt.Sprintf("[CreateInstanceHandler] Instance %s created successfully: configPath=%s, bootAtStart=%v, runUser=%s, additionalProperties=%v", req.InstanceInfo.Name, configPath, req.BootAtStart, runUser, req.Additional)) } func DeleteInstanceHandler(w http.ResponseWriter, r *http.Request) { @@ -289,6 +298,7 @@ func DeleteInstanceHandler(w http.ResponseWriter, r *http.Request) { SendSuccessResponse(w, "Instance deleted successfully", map[string]interface{}{ "name": instanceName, }) + postLog.Info(fmt.Sprintf("[DeleteInstanceHandler] Instance %s deleted successfully", instanceName)) } func ModifyInstanceHandler(w http.ResponseWriter, r *http.Request, field string) { @@ -450,6 +460,7 @@ func ModifyInstanceHandler(w http.ResponseWriter, r *http.Request, field string) "name": newName, "configPath": newConfigPath, }) + postLog.Info(fmt.Sprintf("[ModifyInstanceHandler] Instance %s modified successfully: configPath=%s, bootAtStart=%v, runUser=%s", newName, newConfigPath, newBootAtStart, newRunUser)) } func ListInstancesHandler(w http.ResponseWriter, r *http.Request) { @@ -537,6 +548,18 @@ func generateFrpcConfig(info InstanceInfo) string { return sb.String() } +func addFrpcProxy(info FrpcProxyInfo) string { + var sb strings.Builder + sb.WriteString("[[proxies]]") + sb.WriteString(fmt.Sprintf("name = %s\n", info.Name)) + sb.WriteString(fmt.Sprintf("type = %s\n", info.Type)) + sb.WriteString(fmt.Sprintf("local_ip = %s\n", info.LocalIP)) + sb.WriteString(fmt.Sprintf("local_port = %s\n", info.LocalPort)) + sb.WriteString(fmt.Sprintf("remote_port = %s\n", info.RemotePort)) + + return sb.String() +} + func GetConfigDir() (string, error) { config, err := GetConfig() if err != nil {