mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
35 lines
923 B
Go
35 lines
923 B
Go
package controller
|
|
|
|
import (
|
|
"github.com/mzz2017/v2rayA/common"
|
|
"github.com/mzz2017/v2rayA/db/configure"
|
|
"github.com/mzz2017/v2rayA/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func PostConnection(ctx *gin.Context) {
|
|
var which configure.Which
|
|
err := ctx.ShouldBindJSON(&which)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(nil, "bad request"))
|
|
return
|
|
}
|
|
lastConnectedServer := configure.GetConnectedServer()
|
|
err = service.Connect(&which)
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err, "failed to connect"))
|
|
return
|
|
}
|
|
common.ResponseSuccess(ctx, gin.H{"connectedServer": configure.GetConnectedServer(), "lastConnectedServer": lastConnectedServer})
|
|
}
|
|
|
|
func DeleteConnection(ctx *gin.Context) {
|
|
cs := configure.GetConnectedServer()
|
|
err := service.Disconnect()
|
|
if err != nil {
|
|
common.ResponseError(ctx, logError(err))
|
|
return
|
|
}
|
|
common.ResponseSuccess(ctx, gin.H{"lastConnectedServer": cs})
|
|
}
|