improving client/server info command

This commit is contained in:
2020-06-07 18:31:01 -04:00
parent dd3fd7c4ae
commit 6d738b138d
12 changed files with 72 additions and 31 deletions

View File

@@ -9,7 +9,23 @@ import (
// GetInfo return the relevant repo specific info to the client
func (Server *GVCServer) GetInfo(context echo.Context) error {
repo := context.Param("repoName")
return context.JSON(http.StatusAccepted, 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 {
if knownRepo.RepoName == repo {
repoInfo.BindIP = config.BindIP
repoInfo.Port = config.Port
repoInfo.RawPort = config.RawPort
repoInfo.Version = config.Version
repoInfo.Repo = knownRepo
clients := repoInfo.Repo.KnownClients
for _, client := range clients { // Blank out the client keys
client.Key = ""
}
repoInfo.Repo.KnownClients = clients
}
}
return context.JSONPretty(http.StatusAccepted, repoInfo, " ")
}
// Hello just verifies the server is running //TODO remove this, just extra shit we are sending

View File

@@ -10,3 +10,12 @@ type GVCServer struct {
Config config.GvcServerConfig //contains our full server config
Echo *echo.Echo // Contains our web server instance
}
// RepoInfoRequest is for when a client requests info about a repo
type RepoInfoRequest struct {
Version string
Port int // The port that the server will listed on
BindIP string // What IP to bind the server to. If empty will bind to all interfaces
RawPort int // The optional TCP port that the server will send raw files over
Repo config.RepoConfig //IMPORTANT: We need to blank out the client keys when sending
}

View File

@@ -48,7 +48,7 @@ func main() {
e := echo.New()
server.Echo = e
//Start the routes
e.GET("/hello", server.Hello)
//e.GET("/hello", server.Hello)
e.GET("/info/:repoName", server.GetInfo)
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%d", server.Config.BindIP, server.Config.Port)))
}

View File

@@ -4,3 +4,12 @@ ip = ""
rawport = 0
reporootpath = "F:\\repos"
[[repo]]
rootpath = ""
reponame = "gvc"
defaultbranch = "master"
localbranches = ["master"]
[repo.locked]
[repo.defaultignore]
[repo.nocompress]

View File

@@ -7,13 +7,14 @@ type GvcServerConfig struct {
BindIP string `toml:"ip"` // What IP to bind the server to. If empty will bind to all interfaces
RawPort int `toml:"rawport"` // The optional TCP port that the server will send raw files over
RepoRootPath string `toml:"reporootpath"` // This will be the root path where (by default) all new repos will be stored at
Repos []RepoConfig `toml:"repos"` // A struct of all the repos and their settings for the serve
Repos []RepoConfig `toml:"repo"` // A struct of all the repos and their settings for the serve
}
// RepoConfig will be the struct that holds the config for a single repo
type RepoConfig struct {
KnownClients []Clients `toml:"clients"` //The remote servers for the repo
KnownClients []Clients `toml:"client"` //The remote servers for the repo
RootPath string `toml:"rootpath"` // The absolute path to the root of this particular repo
RepoName string `toml:"reponame"`
DefaultBranch string `toml:"defaultbranch"`
LocalBranches []string `toml:"localbranches"` // LocalBranches constains a string list of branches on the server. Names must be unique. \\TODO: someday add folders like git for branches
Locked FileTypes `toml:"locked"`