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:
@@ -25,6 +25,14 @@ type InstanceInfo struct {
|
|||||||
Additional map[string]interface{} `json:"additionalProperties"`
|
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 {
|
type CreateInstanceRequest struct {
|
||||||
InstanceInfo InstanceInfo `json:"instanceInfo"`
|
InstanceInfo InstanceInfo `json:"instanceInfo"`
|
||||||
BootAtStart bool `json:"bootAtStart"`
|
BootAtStart bool `json:"bootAtStart"`
|
||||||
@@ -195,6 +203,7 @@ func CreateInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
"configPath": configPath,
|
"configPath": configPath,
|
||||||
"bootAtStart": req.BootAtStart,
|
"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) {
|
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{}{
|
SendSuccessResponse(w, "Instance deleted successfully", map[string]interface{}{
|
||||||
"name": instanceName,
|
"name": instanceName,
|
||||||
})
|
})
|
||||||
|
postLog.Info(fmt.Sprintf("[DeleteInstanceHandler] Instance %s deleted successfully", instanceName))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ModifyInstanceHandler(w http.ResponseWriter, r *http.Request, field string) {
|
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,
|
"name": newName,
|
||||||
"configPath": newConfigPath,
|
"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) {
|
func ListInstancesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -537,6 +548,18 @@ func generateFrpcConfig(info InstanceInfo) string {
|
|||||||
return sb.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) {
|
func GetConfigDir() (string, error) {
|
||||||
config, err := GetConfig()
|
config, err := GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user