switching server over to Echo, setting up server struct
This commit is contained in:
@@ -49,10 +49,13 @@ func validateCompress(conf *Gvcconfig) error {
|
||||
for i, folder := range compress.Folders {
|
||||
file, err := os.Stat(folder) // TODO: check to see if it returns ABS or not, might need to convert
|
||||
if err != nil {
|
||||
fmt.Println("unable to find folder listed in array, removing it: ", folder)
|
||||
compress.Folders[i] = compress.Folders[len(compress.Folders)-1]
|
||||
continue
|
||||
}
|
||||
// if err != nil { //TODO: Don't think we should see if it doesn't exits, it may exist in future
|
||||
// fmt.Println("unable to find folder listed in array, removing it: ", folder)
|
||||
// compress.Folders[i] = compress.Folders[len(compress.Folders)-1]
|
||||
// continue
|
||||
// }
|
||||
fileType := file.Mode()
|
||||
if fileType.IsRegular() { // Not a folder
|
||||
fmt.Println("compressed folder in array is not actually a folder, moving it to file compress: ", folder)
|
||||
|
1
go.mod
1
go.mod
@@ -6,5 +6,6 @@ require (
|
||||
github.com/deranjer/clir v1.0.5
|
||||
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031
|
||||
github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d
|
||||
github.com/labstack/echo/v4 v4.1.16 // indirect
|
||||
github.com/smartystreets/goconvey v1.6.4 // indirect
|
||||
)
|
||||
|
38
go.sum
38
go.sum
@@ -1,25 +1,63 @@
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/deranjer/clir v1.0.5 h1:tEunZj5qJLYNBtzMQ/vH8hEAIv4NptWFmTldsP9U2qY=
|
||||
github.com/deranjer/clir v1.0.5/go.mod h1:x/FAjr5CHGsBT0yjs+NYxX3qFxx8G15gbeCcN6FFuyU=
|
||||
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031 h1:sPjxPMNILoBbu6uhDfa97AhlUhTgtPY2HqySAzuLd4o=
|
||||
github.com/deranjer/store v0.0.0-20200526205429-464dd59c6031/go.mod h1:wPOs9IJ77lRTXyjEOQeegCFjIlm21qOFcv33lXmU7gE=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d h1:3/oQzvZhwA8Jb5ykb0KehJfsdHokCJdC96k7xy6SJcs=
|
||||
github.com/firstrow/tcp_server v0.0.0-20190424084220-b7a05ff2879d/go.mod h1:hGkv6sO57ZC+XrSTyzdIGXX7+O6S3RJb9G8sPopEF/4=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/labstack/echo v1.4.4 h1:1bEiBNeGSUKxcPDGfZ/7IgdhJJZx8wV/pICJh4W2NJI=
|
||||
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
|
||||
github.com/labstack/echo/v4 v4.1.16 h1:8swiwjE5Jkai3RPfZoahp8kjVCRNq+y7Q0hPji2Kz0o=
|
||||
github.com/labstack/echo/v4 v4.1.16/go.mod h1:awO+5TzAjvL8XpibdsfXxPgHr+orhtXZJZIQCVjogKI=
|
||||
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
|
||||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||
github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4=
|
||||
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw=
|
||||
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
@@ -1,62 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/deranjer/gvc/messages"
|
||||
"github.com/firstrow/tcp_server"
|
||||
serverconfig "github.com/deranjer/gvc/server/serverconfig"
|
||||
"github.com/deranjer/store"
|
||||
)
|
||||
|
||||
var version = "0.1"
|
||||
|
||||
//This is a generic error message so we make it 'global'
|
||||
var errorMsg = messages.Command{
|
||||
CmdID: messages.ERROR,
|
||||
Body: []byte("Unrecognized Message"),
|
||||
}
|
||||
|
||||
func main() {
|
||||
errMsgJSON, _ := json.Marshal(errorMsg) //creating a []byte to easily send error message
|
||||
server := tcp_server.New("localhost:9999")
|
||||
|
||||
server.OnNewClient(func(c *tcp_server.Client) {
|
||||
// new client connected
|
||||
fmt.Println("New client connected....")
|
||||
newMessage := messages.Command{
|
||||
CmdID: messages.CONNECTED,
|
||||
Body: []byte("Connected"),
|
||||
}
|
||||
jsonMessage, err := json.Marshal(newMessage)
|
||||
if err != nil {
|
||||
log.Fatalf("error creating new marshaller: %s", err)
|
||||
}
|
||||
c.Send(jsonMessage)
|
||||
})
|
||||
server.OnNewMessage(func(c *tcp_server.Client, message []byte) {
|
||||
var newMessage messages.Command
|
||||
//messageBytes := []byte(message)
|
||||
err := json.Unmarshal(message, &newMessage)
|
||||
if err != nil {
|
||||
c.Send(errMsgJSON)
|
||||
fmt.Println("error reading message, closing connection to client")
|
||||
c.Close()
|
||||
}
|
||||
fmt.Println("new Message from client: ", message)
|
||||
switch newMessage.CmdID {
|
||||
case messages.INFO:
|
||||
fmt.Println("Sending server info to client")
|
||||
detailsMessage := fmt.Sprintf("Server Details are as follows: Version: %s \n", version)
|
||||
c.Send(detailsMessage)
|
||||
default:
|
||||
fmt.Println("unrecognized message! ", message)
|
||||
}
|
||||
})
|
||||
server.OnClientConnectionClosed(func(c *tcp_server.Client, err error) {
|
||||
// connection with client lost
|
||||
fmt.Println("Connection with client closed")
|
||||
})
|
||||
|
||||
server.Listen()
|
||||
configPath, err := findConfig()
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to find config file: %s", err)
|
||||
}
|
||||
var conf serverconfig.GvcServerConfig
|
||||
err = store.Load(configPath, &conf)
|
||||
if err != nil {
|
||||
fmt.Printf("Error loading server config file into struct, please fix config, panic! \n%s", err)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
func findConfig() (string, error) {
|
||||
configFile, err := os.Stat("serverConfig.toml")
|
||||
if err != nil {
|
||||
configFile, err := os.Stat("config" + os.PathListSeparator + "serverConfig.toml")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !configFile.IsDir() {
|
||||
return fmt.Sprintf("config" + os.PathListSeparator + "serverConfig.toml"), nil
|
||||
}
|
||||
return "", fmt.Sprintf()
|
||||
}
|
||||
if !configFile.IsDir() {
|
||||
return "serverConfig.toml", nil
|
||||
}
|
||||
}
|
||||
|
75
server/serverconfig/config.go
Normal file
75
server/serverconfig/config.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/deranjer/store"
|
||||
)
|
||||
|
||||
// ConfigPath is the global path to the config that is injected from the main server package.
|
||||
var ConfigPath string
|
||||
|
||||
// ValidateConfig will go through the entire config and do basic sanity checks
|
||||
func ValidateConfig(conf *GvcServerConfig, version string) error {
|
||||
if conf.Version == "" { // No version found, should we update it?
|
||||
fmt.Printf("No version found, inputing current server version: %s\n", version)
|
||||
conf.Version = version
|
||||
}
|
||||
if conf.RootPath == "" {
|
||||
path, err := os.Getwd()
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get current working directory, and rootpath of repo is not set: %s", err)
|
||||
}
|
||||
fmt.Printf("No root path found, inputting current working directory: %s\n", path)
|
||||
}
|
||||
err := validateRemotes(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = validateCompress(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//TODO validate ignores (pretty similar to compress)
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateCompress checks the compression settings to make sure they are valid //TODO return error needed?
|
||||
func validateCompress(conf *GvcServerConfig) error {
|
||||
compress := conf.NoCompress
|
||||
for i, file := range compress.Files {
|
||||
if file == "" {
|
||||
fmt.Println("empty file in compress files, removing... ")
|
||||
compress.Files[i] = compress.Files[len(compress.Files)-1]
|
||||
continue
|
||||
}
|
||||
// TODO: write more validation
|
||||
}
|
||||
for i, folder := range compress.Folders {
|
||||
file, err := os.Stat(folder) // TODO: check to see if it returns ABS or not, might need to convert
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
fileType := file.Mode()
|
||||
if fileType.IsRegular() { // Not a folder
|
||||
fmt.Println("compressed folder in array is not actually a folder, moving it to file compress: ", folder)
|
||||
compress.Folders[i] = compress.Folders[len(compress.Folders)-1]
|
||||
compress.Files = append(compress.Files, folder)
|
||||
continue
|
||||
}
|
||||
}
|
||||
for i, ext := range compress.Exts {
|
||||
if ext == "" {
|
||||
fmt.Println("empty ext in compress exts, removing... ")
|
||||
compress.Exts[i] = compress.Exts[len(compress.Exts)-1]
|
||||
continue
|
||||
}
|
||||
// TODO: validate there is a "." in front of the ext, if not add it?
|
||||
}
|
||||
err := store.Save(ConfigPath, &conf)
|
||||
if err != nil {
|
||||
fmt.Println("Error saving config back to toml file: ", err)
|
||||
}
|
||||
return nil
|
||||
}
|
0
server/serverconfig/serverConfig.toml
Normal file
0
server/serverconfig/serverConfig.toml
Normal file
30
server/serverconfig/structures.go
Normal file
30
server/serverconfig/structures.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package config
|
||||
|
||||
type GvcServerConfig struct {
|
||||
Version string `toml:"version"` // The server version
|
||||
Repos []RepoConfig `toml:"repos"` // A struct of all the repos and their settings for the serve
|
||||
}
|
||||
|
||||
//GvcServerConfig will be the struct that holds the entire server settings
|
||||
type RepoConfig struct {
|
||||
KnownClients []Clients `toml:"clients"` //The remote servers for the repo
|
||||
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"`
|
||||
DefaultIgnores FileTypes `toml:"defaultignore"` //These are the recommended ignores that clients can pull
|
||||
NoCompress FileTypes `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
|
||||
}
|
||||
|
||||
//Clients will be a slice of clients that have authenticated to the server
|
||||
type Clients struct {
|
||||
Name string `toml:"name"`
|
||||
Key string `toml:"key"` //TODO will change this once we figure out authentication
|
||||
LastCommit string `toml:"lastcommit"` //Last commit that this client pushed to the server? not sure if useful
|
||||
}
|
||||
|
||||
//FileTypes is for ignoring files to add or ignoring compress, or for locked files, all use the same type of struct (files, folders and exts)
|
||||
type FileTypes struct {
|
||||
Files []string `toml:"files"`
|
||||
Exts []string `toml:"exts"`
|
||||
Folders []string `toml:"folders"`
|
||||
}
|
Reference in New Issue
Block a user