mirror of
https://gitee.com/goploy/goploy.git
synced 2024-11-29 18:57:59 +08:00
U Optimized code
This commit is contained in:
parent
ea845df302
commit
ba528577fc
@ -7,7 +7,6 @@ import (
|
||||
"github.com/zhenorzz/goploy/core"
|
||||
"github.com/zhenorzz/goploy/model"
|
||||
"github.com/zhenorzz/goploy/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@ -16,7 +15,7 @@ import (
|
||||
type Crontab Controller
|
||||
|
||||
// GetList crontab list
|
||||
func (crontab Crontab) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Crontabs model.Crontabs `json:"list"`
|
||||
}
|
||||
@ -33,7 +32,7 @@ func (crontab Crontab) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Res
|
||||
}
|
||||
|
||||
// GetTotal crontab total
|
||||
func (crontab Crontab) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) GetTotal(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@ -46,7 +45,7 @@ func (crontab Crontab) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Re
|
||||
}
|
||||
|
||||
// GetList crontab list
|
||||
func (crontab Crontab) GetRemoteServerList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) GetRemoteServerList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Crontabs []string `json:"list"`
|
||||
}
|
||||
@ -101,7 +100,7 @@ func (crontab Crontab) GetRemoteServerList(w http.ResponseWriter, gp *core.Goplo
|
||||
}
|
||||
|
||||
// GetBindServerList project detail
|
||||
func (crontab Crontab) GetBindServerList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) GetBindServerList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
CrontabServers model.CrontabServers `json:"list"`
|
||||
}
|
||||
@ -117,7 +116,7 @@ func (crontab Crontab) GetBindServerList(w http.ResponseWriter, gp *core.Goploy)
|
||||
}
|
||||
|
||||
// Add one crontab
|
||||
func (crontab Crontab) Add(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) Add(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Command string `json:"command" validate:"required"`
|
||||
ServerIDs []int64 `json:"serverIds"`
|
||||
@ -164,7 +163,7 @@ func (crontab Crontab) Add(w http.ResponseWriter, gp *core.Goploy) *core.Respons
|
||||
}
|
||||
|
||||
// Edit one crontab
|
||||
func (crontab Crontab) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) Edit(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
Command string `json:"command" validate:"required"`
|
||||
@ -209,7 +208,7 @@ func (crontab Crontab) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Respon
|
||||
}
|
||||
|
||||
// import many crontab
|
||||
func (crontab Crontab) Import(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) Import(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Commands []string `json:"commands" validate:"required"`
|
||||
}
|
||||
@ -257,7 +256,7 @@ func (crontab Crontab) Import(w http.ResponseWriter, gp *core.Goploy) *core.Resp
|
||||
}
|
||||
|
||||
// DeleteRow one Crontab
|
||||
func (crontab Crontab) Remove(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) Remove(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
Radio int8 `json:"radio" validate:"min=0,max=1"`
|
||||
@ -295,7 +294,7 @@ func (crontab Crontab) Remove(w http.ResponseWriter, gp *core.Goploy) *core.Resp
|
||||
}
|
||||
|
||||
// AddServer one crontab
|
||||
func (crontab Crontab) AddServer(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) AddServer(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
CrontabID int64 `json:"crontabId" validate:"gt=0"`
|
||||
ServerIDs []int64 `json:"serverIds" validate:"required"`
|
||||
@ -329,7 +328,7 @@ func (crontab Crontab) AddServer(w http.ResponseWriter, gp *core.Goploy) *core.R
|
||||
}
|
||||
|
||||
// RemoveCrontabServer one crontab
|
||||
func (crontab Crontab) RemoveCrontabServer(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (crontab Crontab) RemoveCrontabServer(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
CrontabServerID int64 `json:"crontabServerId" validate:"gt=0"`
|
||||
CrontabID int64 `json:"crontabId" validate:"gt=0"`
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"github.com/zhenorzz/goploy/model"
|
||||
"github.com/zhenorzz/goploy/service"
|
||||
"github.com/zhenorzz/goploy/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -17,7 +16,7 @@ import (
|
||||
type Deploy Controller
|
||||
|
||||
// GetList -
|
||||
func (deploy Deploy) GetList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (deploy Deploy) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Project model.Projects `json:"list"`
|
||||
}
|
||||
@ -35,7 +34,7 @@ func (deploy Deploy) GetList(w http.ResponseWriter, gp *core.Goploy) *core.Respo
|
||||
}
|
||||
|
||||
// GetPreview deploy detail
|
||||
func (deploy Deploy) GetPreview(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (deploy Deploy) GetPreview(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
GitTraceList model.PublishTraces `json:"gitTraceList"`
|
||||
Pagination model.Pagination `json:"pagination"`
|
||||
@ -71,7 +70,7 @@ func (deploy Deploy) GetPreview(w http.ResponseWriter, gp *core.Goploy) *core.Re
|
||||
}
|
||||
|
||||
// GetDetail deploy detail
|
||||
func (deploy Deploy) GetDetail(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (deploy Deploy) GetDetail(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
PublishTraceList model.PublishTraces `json:"publishTraceList"`
|
||||
}
|
||||
@ -88,7 +87,7 @@ func (deploy Deploy) GetDetail(w http.ResponseWriter, gp *core.Goploy) *core.Res
|
||||
}
|
||||
|
||||
// GetCommitList get latest 10 commit list
|
||||
func (deploy Deploy) GetCommitList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (deploy Deploy) GetCommitList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
CommitList []utils.Commit `json:"commitList"`
|
||||
}
|
||||
@ -126,7 +125,7 @@ func (deploy Deploy) GetCommitList(w http.ResponseWriter, gp *core.Goploy) *core
|
||||
}
|
||||
|
||||
// Publish the project
|
||||
func (deploy Deploy) Publish(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (deploy Deploy) Publish(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ProjectID int64 `json:"projectId" validate:"gt=0"`
|
||||
Commit string `json:"commit"`
|
||||
@ -171,7 +170,7 @@ func (deploy Deploy) Publish(w http.ResponseWriter, gp *core.Goploy) *core.Respo
|
||||
}
|
||||
|
||||
// Webhook connect
|
||||
func (deploy Deploy) Webhook(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (deploy Deploy) Webhook(gp *core.Goploy) *core.Response {
|
||||
projectName := gp.URLQuery.Get("project_name")
|
||||
// other event is blocked in deployMiddleware
|
||||
type ReqData struct {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"github.com/zhenorzz/goploy/core"
|
||||
"github.com/zhenorzz/goploy/model"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@ -13,7 +12,7 @@ import (
|
||||
type Monitor Controller
|
||||
|
||||
// GetList monitor list
|
||||
func (monitor Monitor) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (monitor Monitor) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Monitors model.Monitors `json:"list"`
|
||||
}
|
||||
@ -29,7 +28,7 @@ func (monitor Monitor) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Res
|
||||
}
|
||||
|
||||
// GetList monitor list
|
||||
func (monitor Monitor) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (monitor Monitor) GetTotal(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@ -41,7 +40,7 @@ func (monitor Monitor) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Re
|
||||
}
|
||||
|
||||
// Check one monitor
|
||||
func (monitor Monitor) Check(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (monitor Monitor) Check(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Domain string `json:"domain" validate:"required"`
|
||||
Port int `json:"port" validate:"min=0,max=65535"`
|
||||
@ -58,7 +57,7 @@ func (monitor Monitor) Check(w http.ResponseWriter, gp *core.Goploy) *core.Respo
|
||||
}
|
||||
|
||||
// Add one monitor
|
||||
func (monitor Monitor) Add(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (monitor Monitor) Add(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Domain string `json:"domain" validate:"required"`
|
||||
@ -96,7 +95,7 @@ func (monitor Monitor) Add(w http.ResponseWriter, gp *core.Goploy) *core.Respons
|
||||
}
|
||||
|
||||
// Edit one monitor
|
||||
func (monitor Monitor) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (monitor Monitor) Edit(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
@ -131,7 +130,7 @@ func (monitor Monitor) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Respon
|
||||
}
|
||||
|
||||
// Stop one Monitor
|
||||
func (monitor Monitor) Toggle(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (monitor Monitor) Toggle(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
}
|
||||
@ -147,7 +146,7 @@ func (monitor Monitor) Toggle(w http.ResponseWriter, gp *core.Goploy) *core.Resp
|
||||
}
|
||||
|
||||
// RemoveRow one Monitor
|
||||
func (monitor Monitor) Remove(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (monitor Monitor) Remove(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package controller
|
||||
import (
|
||||
"github.com/zhenorzz/goploy/core"
|
||||
"github.com/zhenorzz/goploy/model"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -11,7 +10,7 @@ import (
|
||||
type Namespace Controller
|
||||
|
||||
// GetList namespace list
|
||||
func (namespace Namespace) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (namespace Namespace) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Namespaces model.Namespaces `json:"list"`
|
||||
}
|
||||
@ -28,7 +27,7 @@ func (namespace Namespace) GetList(_ http.ResponseWriter, gp *core.Goploy) *core
|
||||
}
|
||||
|
||||
// GetList server list
|
||||
func (namespace Namespace) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (namespace Namespace) GetTotal(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@ -40,7 +39,7 @@ func (namespace Namespace) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *cor
|
||||
}
|
||||
|
||||
// GetUserOption user list
|
||||
func (namespace Namespace) GetUserOption(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (namespace Namespace) GetUserOption(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
NamespaceUsers model.NamespaceUsers `json:"list"`
|
||||
}
|
||||
@ -53,7 +52,7 @@ func (namespace Namespace) GetUserOption(_ http.ResponseWriter, gp *core.Goploy)
|
||||
}
|
||||
|
||||
// GetBindUserList user list
|
||||
func (namespace Namespace) GetBindUserList(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (namespace Namespace) GetBindUserList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
NamespaceUsers model.NamespaceUsers `json:"list"`
|
||||
}
|
||||
@ -69,7 +68,7 @@ func (namespace Namespace) GetBindUserList(_ http.ResponseWriter, gp *core.Goplo
|
||||
}
|
||||
|
||||
// Add one namespace
|
||||
func (namespace Namespace) Add(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (namespace Namespace) Add(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
}
|
||||
@ -94,7 +93,7 @@ func (namespace Namespace) Add(_ http.ResponseWriter, gp *core.Goploy) *core.Res
|
||||
}
|
||||
|
||||
// Edit one namespace
|
||||
func (namespace Namespace) Edit(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (namespace Namespace) Edit(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
@ -115,7 +114,7 @@ func (namespace Namespace) Edit(_ http.ResponseWriter, gp *core.Goploy) *core.Re
|
||||
}
|
||||
|
||||
// AddUser to namespace
|
||||
func (namespace Namespace) AddUser(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (namespace Namespace) AddUser(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
NamespaceID int64 `json:"namespaceId" validate:"gt=0"`
|
||||
UserIDs []int64 `json:"userIds" validate:"required"`
|
||||
@ -151,7 +150,7 @@ func (namespace Namespace) AddUser(_ http.ResponseWriter, gp *core.Goploy) *core
|
||||
}
|
||||
|
||||
// RemoveUser from namespace
|
||||
func (namespace Namespace) RemoveUser(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (namespace Namespace) RemoveUser(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
NamespaceUserID int64 `json:"namespaceUserId" validate:"gt=0"`
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package controller
|
||||
import (
|
||||
"database/sql"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/zhenorzz/goploy/core"
|
||||
@ -14,7 +13,7 @@ import (
|
||||
type Package Controller
|
||||
|
||||
// GetList list
|
||||
func (Package) GetList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Package) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Packages model.Packages `json:"list"`
|
||||
}
|
||||
@ -30,7 +29,7 @@ func (Package) GetList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// GetTotal total
|
||||
func (Package) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Package) GetTotal(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@ -43,7 +42,7 @@ func (Package) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// GetOption list
|
||||
func (Package) GetOption(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Package) GetOption(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Packages model.Packages `json:"list"`
|
||||
}
|
||||
@ -56,7 +55,7 @@ func (Package) GetOption(w http.ResponseWriter, gp *core.Goploy) *core.Response
|
||||
}
|
||||
|
||||
// Upload file
|
||||
func (Package) Upload(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Package) Upload(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Filename string `json:"filename"`
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"github.com/zhenorzz/goploy/core"
|
||||
"github.com/zhenorzz/goploy/model"
|
||||
"github.com/zhenorzz/goploy/utils"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@ -19,7 +18,7 @@ import (
|
||||
type Project Controller
|
||||
|
||||
// GetList -
|
||||
func (project Project) GetList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Projects model.Projects `json:"list"`
|
||||
}
|
||||
@ -36,7 +35,7 @@ func (project Project) GetList(w http.ResponseWriter, gp *core.Goploy) *core.Res
|
||||
}
|
||||
|
||||
// GetTotal -
|
||||
func (project Project) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) GetTotal(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@ -51,7 +50,7 @@ func (project Project) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Re
|
||||
}
|
||||
|
||||
// GetRemoteBranchList -
|
||||
func (project Project) GetRemoteBranchList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) GetRemoteBranchList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Branch []string `json:"branch"`
|
||||
}
|
||||
@ -78,7 +77,7 @@ func (project Project) GetRemoteBranchList(w http.ResponseWriter, gp *core.Goplo
|
||||
}
|
||||
|
||||
// GetBindServerList -
|
||||
func (project Project) GetBindServerList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) GetBindServerList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
ProjectServers model.ProjectServers `json:"list"`
|
||||
}
|
||||
@ -94,7 +93,7 @@ func (project Project) GetBindServerList(w http.ResponseWriter, gp *core.Goploy)
|
||||
}
|
||||
|
||||
// GetBindUserList -
|
||||
func (project Project) GetBindUserList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) GetBindUserList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
ProjectUsers model.ProjectUsers `json:"list"`
|
||||
}
|
||||
@ -110,7 +109,7 @@ func (project Project) GetBindUserList(w http.ResponseWriter, gp *core.Goploy) *
|
||||
}
|
||||
|
||||
// Add project
|
||||
func (project Project) Add(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) Add(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
URL string `json:"url" validate:"required"`
|
||||
@ -206,7 +205,7 @@ func (project Project) Add(w http.ResponseWriter, gp *core.Goploy) *core.Respons
|
||||
}
|
||||
|
||||
// Edit project
|
||||
func (project Project) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) Edit(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
Name string `json:"name"`
|
||||
@ -314,7 +313,7 @@ func (project Project) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Respon
|
||||
}
|
||||
|
||||
// RemoveRow Project
|
||||
func (project Project) Remove(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) Remove(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
}
|
||||
@ -341,7 +340,7 @@ func (project Project) Remove(w http.ResponseWriter, gp *core.Goploy) *core.Resp
|
||||
}
|
||||
|
||||
// AddServer to project
|
||||
func (project Project) AddServer(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) AddServer(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ProjectID int64 `json:"projectId" validate:"gt=0"`
|
||||
ServerIDs []int64 `json:"serverIds" validate:"required"`
|
||||
@ -369,7 +368,7 @@ func (project Project) AddServer(w http.ResponseWriter, gp *core.Goploy) *core.R
|
||||
}
|
||||
|
||||
// AddUser to project
|
||||
func (project Project) AddUser(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) AddUser(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ProjectID int64 `json:"projectId" validate:"gt=0"`
|
||||
UserIDs []int64 `json:"userIds" validate:"required"`
|
||||
@ -396,7 +395,7 @@ func (project Project) AddUser(w http.ResponseWriter, gp *core.Goploy) *core.Res
|
||||
}
|
||||
|
||||
// RemoveServer from Project
|
||||
func (project Project) RemoveServer(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) RemoveServer(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ProjectServerID int64 `json:"projectServerId" validate:"gt=0"`
|
||||
}
|
||||
@ -412,7 +411,7 @@ func (project Project) RemoveServer(w http.ResponseWriter, gp *core.Goploy) *cor
|
||||
}
|
||||
|
||||
// RemoveUser from Project
|
||||
func (project Project) RemoveUser(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) RemoveUser(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ProjectUserID int64 `json:"projectUserId" validate:"gt=0"`
|
||||
}
|
||||
@ -429,7 +428,7 @@ func (project Project) RemoveUser(w http.ResponseWriter, gp *core.Goploy) *core.
|
||||
}
|
||||
|
||||
// GetTaskList -
|
||||
func (project Project) GetTaskList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) GetTaskList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
ProjectTask model.ProjectTasks `json:"projectTaskList"`
|
||||
Pagination model.Pagination `json:"pagination"`
|
||||
@ -451,7 +450,7 @@ func (project Project) GetTaskList(w http.ResponseWriter, gp *core.Goploy) *core
|
||||
}
|
||||
|
||||
// AddTask to project
|
||||
func (project Project) AddTask(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) AddTask(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ProjectID int64 `json:"projectId" validate:"gt=0"`
|
||||
CommitID string `json:"commitId" validate:"len=40"`
|
||||
@ -481,7 +480,7 @@ func (project Project) AddTask(w http.ResponseWriter, gp *core.Goploy) *core.Res
|
||||
}
|
||||
|
||||
// EditTask from project
|
||||
func (project Project) EditTask(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) EditTask(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
CommitID string `json:"commitId" validate:"len=40"`
|
||||
@ -509,7 +508,7 @@ func (project Project) EditTask(w http.ResponseWriter, gp *core.Goploy) *core.Re
|
||||
}
|
||||
|
||||
// RemoveTask from project
|
||||
func (project Project) RemoveTask(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (project Project) RemoveTask(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"gopkg.in/go-playground/validator.v9"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -21,7 +20,7 @@ import (
|
||||
type Server Controller
|
||||
|
||||
// GetList -
|
||||
func (server Server) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Servers model.Servers `json:"list"`
|
||||
}
|
||||
@ -37,7 +36,7 @@ func (server Server) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Respo
|
||||
}
|
||||
|
||||
// GetTotal -
|
||||
func (server Server) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) GetTotal(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@ -49,7 +48,7 @@ func (server Server) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Resp
|
||||
}
|
||||
|
||||
// GetInstallPreview server install preview list
|
||||
func (server Server) GetInstallPreview(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) GetInstallPreview(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
InstallTraceList model.InstallTraces `json:"installTraceList"`
|
||||
}
|
||||
@ -65,7 +64,7 @@ func (server Server) GetInstallPreview(_ http.ResponseWriter, gp *core.Goploy) *
|
||||
}
|
||||
|
||||
// GetInstallList server install list by token
|
||||
func (server Server) GetInstallList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) GetInstallList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
InstallTraceList model.InstallTraces `json:"installTraceList"`
|
||||
}
|
||||
@ -83,7 +82,7 @@ func (server Server) GetInstallList(w http.ResponseWriter, gp *core.Goploy) *cor
|
||||
}
|
||||
|
||||
// GetOption -
|
||||
func (server Server) GetOption(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) GetOption(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Servers model.Servers `json:"list"`
|
||||
}
|
||||
@ -96,7 +95,7 @@ func (server Server) GetOption(w http.ResponseWriter, gp *core.Goploy) *core.Res
|
||||
}
|
||||
|
||||
// Check server
|
||||
func (server Server) Check(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) Check(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
IP string `json:"ip" validate:"ip4_addr"`
|
||||
Port int `json:"port" validate:"min=0,max=65535"`
|
||||
@ -113,7 +112,7 @@ func (server Server) Check(w http.ResponseWriter, gp *core.Goploy) *core.Respons
|
||||
}
|
||||
|
||||
// Add server
|
||||
func (server Server) Add(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) Add(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
IP string `json:"ip" validate:"ip4_addr"`
|
||||
@ -146,7 +145,7 @@ func (server Server) Add(w http.ResponseWriter, gp *core.Goploy) *core.Response
|
||||
}
|
||||
|
||||
// Edit server
|
||||
func (server Server) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) Edit(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
@ -175,7 +174,7 @@ func (server Server) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Response
|
||||
}
|
||||
|
||||
// RemoveRow server
|
||||
func (server Server) Remove(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) Remove(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
}
|
||||
@ -191,7 +190,7 @@ func (server Server) Remove(w http.ResponseWriter, gp *core.Goploy) *core.Respon
|
||||
}
|
||||
|
||||
// Install Server Environment
|
||||
func (server Server) Install(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (server Server) Install(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ServerID int64 `json:"serverId" validate:"gt=0"`
|
||||
TemplateID int64 `json:"templateId" validate:"gt=0"`
|
||||
|
@ -1,8 +1,6 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zhenorzz/goploy/core"
|
||||
"github.com/zhenorzz/goploy/model"
|
||||
)
|
||||
@ -11,7 +9,7 @@ import (
|
||||
type Template Controller
|
||||
|
||||
// GetList -
|
||||
func (Template) GetList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Template) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Templates model.Templates `json:"list"`
|
||||
}
|
||||
@ -27,7 +25,7 @@ func (Template) GetList(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// GetTotal -
|
||||
func (Template) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Template) GetTotal(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@ -39,7 +37,7 @@ func (Template) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response
|
||||
}
|
||||
|
||||
// GetOption -
|
||||
func (Template) GetOption(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Template) GetOption(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Templates model.Templates `json:"list"`
|
||||
}
|
||||
@ -52,7 +50,7 @@ func (Template) GetOption(w http.ResponseWriter, gp *core.Goploy) *core.Response
|
||||
}
|
||||
|
||||
// Add template
|
||||
func (Template) Add(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Template) Add(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Remark string `json:"remark"`
|
||||
@ -83,7 +81,7 @@ func (Template) Add(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// Edit template
|
||||
func (Template) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Template) Edit(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
@ -110,7 +108,7 @@ func (Template) Edit(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// RemoveRow Template
|
||||
func (Template) Remove(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (Template) Remove(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
type User Controller
|
||||
|
||||
// Login -
|
||||
func (user User) Login(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) Login(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Account string `json:"account" validate:"min=5,max=12"`
|
||||
Password string `json:"password" validate:"password"`
|
||||
@ -62,12 +62,12 @@ func (user User) Login(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
core.Cache.Set("namespace:"+strconv.Itoa(int(userData.ID)), &namespaceList, cache.DefaultExpiration)
|
||||
|
||||
cookie := http.Cookie{Name: core.LoginCookieName, Value: token, Path: "/", MaxAge: 86400, HttpOnly: true}
|
||||
http.SetCookie(w, &cookie)
|
||||
http.SetCookie(gp.ResponseWriter, &cookie)
|
||||
return &core.Response{Data: RespData{Token: token, NamespaceList: namespaceList}}
|
||||
}
|
||||
|
||||
// Info -
|
||||
func (user User) Info(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) Info(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
UserInfo struct {
|
||||
ID int64 `json:"id"`
|
||||
@ -85,7 +85,7 @@ func (user User) Info(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// GetList -
|
||||
func (user User) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) GetList(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Users model.Users `json:"list"`
|
||||
}
|
||||
@ -101,7 +101,7 @@ func (user User) GetList(_ http.ResponseWriter, gp *core.Goploy) *core.Response
|
||||
}
|
||||
|
||||
// GetTotal -
|
||||
func (user User) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) GetTotal(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
@ -114,7 +114,7 @@ func (user User) GetTotal(_ http.ResponseWriter, gp *core.Goploy) *core.Response
|
||||
}
|
||||
|
||||
// GetOption -
|
||||
func (user User) GetOption(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) GetOption(gp *core.Goploy) *core.Response {
|
||||
type RespData struct {
|
||||
Users model.Users `json:"list"`
|
||||
}
|
||||
@ -126,7 +126,7 @@ func (user User) GetOption(_ http.ResponseWriter, gp *core.Goploy) *core.Respons
|
||||
}
|
||||
|
||||
// Add user
|
||||
func (user User) Add(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) Add(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
Account string `json:"account" validate:"min=5,max=12"`
|
||||
Password string `json:"password" validate:"omitempty,password"`
|
||||
@ -173,7 +173,7 @@ func (user User) Add(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// Edit user
|
||||
func (user User) Edit(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) Edit(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
Password string `json:"password" validate:"omitempty,password"`
|
||||
@ -220,7 +220,7 @@ func (user User) Edit(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// RemoveRow User
|
||||
func (user User) Remove(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) Remove(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
ID int64 `json:"id" validate:"gt=0"`
|
||||
}
|
||||
@ -238,7 +238,7 @@ func (user User) Remove(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
}
|
||||
|
||||
// ChangePassword -
|
||||
func (user User) ChangePassword(_ http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (user User) ChangePassword(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
OldPassword string `json:"oldPwd" validate:"password"`
|
||||
NewPassword string `json:"newPwd" validate:"password"`
|
||||
|
@ -31,6 +31,7 @@ type Goploy struct {
|
||||
UserInfo model.User
|
||||
Namespace model.Namespace
|
||||
Request *http.Request
|
||||
ResponseWriter http.ResponseWriter
|
||||
URLQuery url.Values
|
||||
Body []byte
|
||||
}
|
||||
@ -40,15 +41,15 @@ type route struct {
|
||||
pattern string // 正则表达式
|
||||
method string // Method specifies the HTTP method (GET, POST, PUT, etc.).
|
||||
roles []string //允许的角色
|
||||
callback func(w http.ResponseWriter, gp *Goploy) *Response //Controller函数
|
||||
middlewares []func(w http.ResponseWriter, gp *Goploy) error //中间件
|
||||
callback func(gp *Goploy) *Response //Controller函数
|
||||
middlewares []func(gp *Goploy) error //中间件
|
||||
}
|
||||
|
||||
// Router is route slice and global middlewares
|
||||
type Router struct {
|
||||
whiteList map[string]struct{}
|
||||
routes []route
|
||||
middlewares []func(w http.ResponseWriter, gp *Goploy) error //中间件
|
||||
middlewares []func(gp *Goploy) error //中间件
|
||||
}
|
||||
|
||||
// Start a router
|
||||
@ -71,7 +72,7 @@ func (rt *Router) RegisterWhiteList(whiteList map[string]struct{}) {
|
||||
// Add router
|
||||
// pattern path
|
||||
// callback where path should be handle
|
||||
func (rt *Router) Add(pattern, method string, callback func(w http.ResponseWriter, gp *Goploy) *Response, middleware ...func(w http.ResponseWriter, gp *Goploy) error) *Router {
|
||||
func (rt *Router) Add(pattern, method string, callback func(gp *Goploy) *Response, middleware ...func(gp *Goploy) error) *Router {
|
||||
r := route{pattern: pattern, method: method, callback: callback}
|
||||
for _, m := range middleware {
|
||||
r.middlewares = append(r.middlewares, m)
|
||||
@ -93,7 +94,7 @@ func (rt *Router) Role(role string) *Router {
|
||||
}
|
||||
|
||||
// Middleware global Middleware handle function
|
||||
func (rt *Router) Middleware(middleware func(w http.ResponseWriter, gp *Goploy) error) {
|
||||
func (rt *Router) Middleware(middleware func(gp *Goploy) error) {
|
||||
rt.middlewares = append(rt.middlewares, middleware)
|
||||
}
|
||||
|
||||
@ -123,7 +124,7 @@ func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
response = rt.doRequest(w, gp)
|
||||
response = rt.doRequest(gp)
|
||||
if response != nil {
|
||||
response.JSON(w)
|
||||
}
|
||||
@ -197,16 +198,17 @@ func (rt *Router) checkLogin(w http.ResponseWriter, r *http.Request) (*Goploy, *
|
||||
UserInfo: userInfo,
|
||||
Namespace: namespace,
|
||||
Request: r,
|
||||
ResponseWriter: w,
|
||||
URLQuery: r.URL.Query(),
|
||||
Body: body,
|
||||
}
|
||||
return gp, nil
|
||||
}
|
||||
|
||||
func (rt *Router) doRequest(w http.ResponseWriter, gp *Goploy) *Response {
|
||||
func (rt *Router) doRequest(gp *Goploy) *Response {
|
||||
|
||||
for _, middleware := range rt.middlewares {
|
||||
err := middleware(w, gp)
|
||||
err := middleware(gp)
|
||||
if err != nil {
|
||||
return &Response{Code: Error, Message: err.Error()}
|
||||
}
|
||||
@ -221,12 +223,12 @@ func (rt *Router) doRequest(w http.ResponseWriter, gp *Goploy) *Response {
|
||||
}
|
||||
for _, middleware := range route.middlewares {
|
||||
|
||||
if err := middleware(w, gp); err != nil {
|
||||
if err := middleware(gp); err != nil {
|
||||
return &Response{Code: Error, Message: err.Error()}
|
||||
}
|
||||
}
|
||||
|
||||
return route.callback(w, gp)
|
||||
return route.callback(gp)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,14 +3,12 @@ package middleware
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zhenorzz/goploy/core"
|
||||
"github.com/zhenorzz/goploy/model"
|
||||
)
|
||||
|
||||
// HasPublishAuth check the user has publish auth
|
||||
func HasPublishAuth(_ http.ResponseWriter, gp *core.Goploy) error {
|
||||
func HasPublishAuth(gp *core.Goploy) error {
|
||||
type ReqData struct {
|
||||
ProjectID int64 `json:"projectId"`
|
||||
}
|
||||
@ -27,7 +25,7 @@ func HasPublishAuth(_ http.ResponseWriter, gp *core.Goploy) error {
|
||||
}
|
||||
|
||||
// FilterEvent check the webhook event has publish auth
|
||||
func FilterEvent(_ http.ResponseWriter, gp *core.Goploy) error {
|
||||
func FilterEvent(gp *core.Goploy) error {
|
||||
|
||||
if XGitHubEvent := gp.Request.Header.Get("X-GitHub-Event"); len(XGitHubEvent) != 0 && XGitHubEvent == "push" {
|
||||
return nil
|
||||
|
4
ws/WS.go
4
ws/WS.go
@ -81,7 +81,7 @@ func GetHub() *Hub {
|
||||
}
|
||||
|
||||
// Connect the publish information in websocket
|
||||
func (hub *Hub) Connect(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
func (hub *Hub) Connect(gp *core.Goploy) *core.Response {
|
||||
upgrader := websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool {
|
||||
if strings.Contains(r.Header.Get("origin"), strings.Split(r.Host, ":")[0]) {
|
||||
@ -90,7 +90,7 @@ func (hub *Hub) Connect(w http.ResponseWriter, gp *core.Goploy) *core.Response {
|
||||
return false
|
||||
},
|
||||
}
|
||||
c, err := upgrader.Upgrade(w, gp.Request, nil)
|
||||
c, err := upgrader.Upgrade(gp.ResponseWriter, gp.Request, nil)
|
||||
if err != nil {
|
||||
core.Log(core.ERROR, err.Error())
|
||||
return &core.Response{Code: core.Error, Message: err.Error()}
|
||||
|
Loading…
Reference in New Issue
Block a user