adding more server/client communication commands, need to fix echo path params

This commit is contained in:
2020-06-08 20:55:34 -04:00
parent b2238657c8
commit c2e74ce7f4
10 changed files with 111 additions and 33 deletions

View File

@@ -4,12 +4,15 @@ import (
"fmt"
"net/http"
"github.com/deranjer/gvc/common"
serverconfig "github.com/deranjer/gvc/server/serverconfig"
"github.com/labstack/echo"
)
// GetInfo return the relevant repo specific info to the client
func (Server *GVCServer) GetInfo(context echo.Context) error {
repo := context.Param("repoName")
repo := context.Param("repo")
fmt.Println("Asking about repo: ", repo)
config := Server.Config
var repoInfo RepoInfoRequest // Create an engine struct that contains basic server info as well as all repo info
for _, knownRepo := range config.Repos {
@@ -31,14 +34,57 @@ func (Server *GVCServer) GetInfo(context echo.Context) error {
func (Server *GVCServer) LockFile(context echo.Context) error {
fileType := context.Param("type")
fileName := context.Param("name")
repoName := context.Param("repo")
var repo serverconfig.RepoConfig
for i, knownRepo := range Server.Config.Repos {
if knownRepo.RepoName == repoName {
repo = Server.Config.Repos[i]
}
}
switch fileType {
case "file":
//common.CheckFileTypes(fileName, fileType,)
err := common.CheckFileTypes(fileName, fileType, repo.Locked)
if err != nil {
return fmt.Errorf("failed checking file lock: %s", err)
}
fmt.Println("Filename: ", fileName)
}
return nil
}
// Refresh sends all updated information to client (like git fetch)
func (Server *GVCServer) Refresh(context echo.Context) error {
repoName := context.Param("repo")
var serverRepo serverconfig.RepoConfig
for i, repo := range Server.Config.Repos {
if repo.RepoName == repoName {
serverRepo = Server.Config.Repos[i]
}
}
// pull the locks and ignores to send back to client
branches := serverRepo.LocalBranches
serverLocks := serverRepo.Locked
serverIgnores := serverRepo.DefaultIgnores
refreshResult := common.RepoRefreshRequest{
Branches: branches,
Locked: serverLocks,
Ignores: serverIgnores,
}
return context.JSON(http.StatusOK, refreshResult)
}
// Revert fetches the supplied file (or entire repo) at version X and pushes it to the client // TODO: This should perhaps just be part of PULL?
func (Server *GVCServer) Revert(context echo.Context) error {
repoName := context.Param("repo")
return context.JSON(http.StatusOK, repoName)
}
// Pull fetches the latest changes from the server to the client.
func (Server *GVCServer) Pull(context echo.Context) error {
helloMsg := "server alive"
return context.JSON(http.StatusOK, helloMsg)
}
// Hello just verifies the server is running //TODO remove this, just extra shit we are sending
func (Server *GVCServer) Hello(context echo.Context) error {
helloMsg := "server alive"

View File

@@ -49,7 +49,10 @@ func main() {
server.Echo = e
//Start the routes
//e.GET("/hello", server.Hello)
e.GET("/info/:repoName", server.GetInfo)
e.GET("/lock/:type/:name", server.LockFile)
e.GET("/:repo/info/", server.GetInfo)
e.GET("/:repo/lock/:type/:name", server.LockFile)
e.GET("/:repo/refresh", server.Refresh)
e.GET("/:repo/revert/:hash", server.Revert) // TODO: Might not need this, just add extra args to pull?
e.GET("/:repo/pull/:branch", server.Pull)
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port)))
}

View File

@@ -15,6 +15,7 @@ reporootpath = "F:\\repos"
key = "12345"
lastcommit = "4343434343434"
[repo.locked]
files = ["client1.exe", "client2.exe"]
[repo.defaultignore]
[repo.nocompress]