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
This commit is contained in:
2026-03-02 13:20:38 +08:00
parent d2d92e222d
commit 75642fb415
+23
View File
@@ -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 {