diff --git a/README.md b/README.md index 7100de9e164b8a54ad2c7cb8c9735938f5098d36..21f29829e303d321da593a43d14113f1047700a8 100644 --- a/README.md +++ b/README.md @@ -56,17 +56,23 @@ Server: The following placeholders can be used in the Commandline. - | Placeholder | Description | | ----------- |------------------------------------------------| | `Path` | The Watched Path | | `IsDir` | Is the Path a directory? | | `Directory` | If the path is a file, then the directory here | | `WebPath` | The Web Path | +| `ConfigPath` | The Config Path | | `PID` | The Process ID (Server) | | `Bin` | The command used to start the server. | | `Call` | The entire call | +The `!reload` command can be used to send the browser a message to reload the page. +The command must be enclosed in quotation marks. + +```bash + + ### Server Start server and deliver files. diff --git a/application/source/go.mod b/application/source/go.mod index 1e9a26471be2edc131c816a11823ee0e161ca6e8..9b1e6820cfe0874ba51ef99b094b4fbd906ed24d 100644 --- a/application/source/go.mod +++ b/application/source/go.mod @@ -18,14 +18,24 @@ require ( require ( bitbucket.org/creachadair/shell v0.0.7 // indirect + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.1.1 // indirect + github.com/Masterminds/sprig/v3 v3.2.2 // indirect github.com/bitfield/script v0.20.2 // indirect github.com/dave/jennifer v1.5.1 // indirect github.com/evanw/esbuild v0.15.6 // indirect + github.com/huandu/xstrings v1.3.1 // indirect + github.com/imdario/mergo v0.3.11 // indirect github.com/itchyny/gojq v0.12.7 // indirect github.com/itchyny/timefmt-go v0.1.3 // indirect + github.com/mitchellh/copystructure v1.0.0 // indirect + github.com/mitchellh/reflectwalk v1.0.0 // indirect + github.com/shopspring/decimal v1.2.0 // indirect + github.com/spf13/cast v1.3.1 // indirect github.com/unknwon/com v1.0.1 // indirect github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect ) diff --git a/application/source/go.sum b/application/source/go.sum index 27300027fa4acdd1dc8a52fd5a4b28fb64c66832..d47dab53d7cf2b6e2652b57459c3913ce52c42de 100644 --- a/application/source/go.sum +++ b/application/source/go.sum @@ -2,6 +2,12 @@ bitbucket.org/creachadair/shell v0.0.7 h1:Z96pB6DkSb7F3Y3BBnJeOZH2gazyMTWlvecSD4 bitbucket.org/creachadair/shell v0.0.7/go.mod h1:oqtXSSvSYr4624lnnabXHaBsYW6RD80caLi2b3hJk0U= gitea.com/go-chi/session v0.0.0-20211218221615-e3605d8b28b8 h1:tJQRXgZigkLeeW9LPlps9G9aMoE6LAmqigLA+wxmd1Q= gitea.com/go-chi/session v0.0.0-20211218221615-e3605d8b28b8/go.mod h1:fc/pjt5EqNKgqQXYzcas1Z5L5whkZHyOvTA7OzWVJck= +github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= +github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= +github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8= +github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/bitfield/script v0.20.2 h1:4DexsRtBILVMEn3EZwHbtJdDqdk43sXI8gM3F04JXgs= github.com/bitfield/script v0.20.2/go.mod h1:l3AZPVAtKQrL03bwh7nlNTUtgrgSWurpJSbtqspYrOA= @@ -46,6 +52,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ= @@ -56,6 +63,10 @@ github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORR github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs= +github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= +github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/itchyny/gojq v0.12.7 h1:hYPTpeWfrJ1OT+2j6cvBScbhl0TkdwGM4bc66onUSOQ= github.com/itchyny/gojq v0.12.7/go.mod h1:ZdvNHVlzPgUf8pgjnuDTmGfHA/21KoutQUJ3An/xNuw= github.com/itchyny/timefmt-go v0.1.3 h1:7M3LGVDsqcd0VZH2U+x393obrzZisp7C0uEe921iRkU= @@ -68,6 +79,10 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= +github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -84,6 +99,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sethvargo/go-envconfig v0.8.2 h1:DDUVuG21RMgeB/bn4leclUI/837y6cQCD4w8hb5797k= github.com/sethvargo/go-envconfig v0.8.2/go.mod h1:Iz1Gy1Sf3T64TQlJSvee81qDhf7YIlt8GMUX6yyNFs0= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw= github.com/siddontang/ledisdb v0.0.0-20190202134119-8ceb77e66a92/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg= github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA= @@ -93,8 +110,12 @@ github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1 github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= @@ -112,6 +133,8 @@ go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9i go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY= go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -157,6 +180,7 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/application/source/watch/dataset.go b/application/source/watch/dataset.go index d3cc1a6b3db9571cf1fae001cd826eee12424538..3f2f8dcef4d073d9ab493b9b711b0f1500358b1a 100644 --- a/application/source/watch/dataset.go +++ b/application/source/watch/dataset.go @@ -1,81 +1,82 @@ package watch -import ( - "gitlab.schukai.com/oss/utilities/conan/configuration" - "gitlab.schukai.com/oss/utilities/conan/constants" - "path" -) - -func getScriptName() string { - return "app.js" -} -func getStyleName() string { - return "app.css" -} - -func newDataset(appID string) *Dataset { - - webPath := configuration.GetServerWebPath() - - scriptName := getScriptName() - relScriptPath := path.Join(appID, constants.AppScriptDirectory) - absScriptPath := path.Join(webPath, relScriptPath) - scriptHash := GetFileHash(path.Join(absScriptPath, scriptName)) - relScriptPath = path.Join("/", relScriptPath, scriptHash, scriptName) - - styleName := getStyleName() - relStylePath := path.Join(appID, constants.AppStyleDirectory) - absStylePath := path.Join(webPath, relStylePath) - styleHash := GetFileHash(path.Join(absStylePath, styleName)) - relStylePath = path.Join("/", relStylePath, styleHash, styleName) - - manifestPath := path.Join("/", appID, constants.WebManifestName) - faviconPath := path.Join("/", appID, constants.FaviconName) - - tags := &Tags{ - Config: "", - WebManifest: "<link rel=\"manifest\" href=\"" + manifestPath + "\" crossorigin=\"use-credentials\">", - Favicon: "<link rel=\"icon\" href=\"" + faviconPath + "\">", - Script: "<script type=\"module\" src=\"" + relScriptPath + "\"></script>", - Style: "<link rel=\"stylesheet\" href=\"" + relStylePath + "\">", - Cache: "<meta http-equiv=\"cache-control\" content=\"" + constants.StandardCacheControl + "\">", - } - - meta := &Meta{ - Language: "en", - } - - dataset := &Dataset{ - Mnemonic: appID, - Tags: tags, - Meta: meta, - } - - return dataset - -} - -type Meta struct { - Language string -} - -type Resources struct { - Script string - Style string -} - -type Tags struct { - Config string - WebManifest string - Favicon string - Script string - Style string - Cache string -} - -type Dataset struct { - Mnemonic string - *Tags - *Meta - *Resources -} +// +//import ( +// "gitlab.schukai.com/oss/utilities/conan/configuration" +// "gitlab.schukai.com/oss/utilities/conan/constants" +// "path" +//) +// +//func getScriptName() string { +// return "app.js" +//} +//func getStyleName() string { +// return "app.css" +//} +// +//func newDataset(appID string) *Dataset { +// +// webPath := configuration.GetServerWebPath() +// +// scriptName := getScriptName() +// relScriptPath := path.Join(appID, constants.AppScriptDirectory) +// absScriptPath := path.Join(webPath, relScriptPath) +// scriptHash := GetFileHash(path.Join(absScriptPath, scriptName)) +// relScriptPath = path.Join("/", relScriptPath, scriptHash, scriptName) +// +// styleName := getStyleName() +// relStylePath := path.Join(appID, constants.AppStyleDirectory) +// absStylePath := path.Join(webPath, relStylePath) +// styleHash := GetFileHash(path.Join(absStylePath, styleName)) +// relStylePath = path.Join("/", relStylePath, styleHash, styleName) +// +// manifestPath := path.Join("/", appID, constants.WebManifestName) +// faviconPath := path.Join("/", appID, constants.FaviconName) +// +// tags := &Tags{ +// Config: "", +// WebManifest: "<link rel=\"manifest\" href=\"" + manifestPath + "\" crossorigin=\"use-credentials\">", +// Favicon: "<link rel=\"icon\" href=\"" + faviconPath + "\">", +// Script: "<script type=\"module\" src=\"" + relScriptPath + "\"></script>", +// Style: "<link rel=\"stylesheet\" href=\"" + relStylePath + "\">", +// Cache: "<meta http-equiv=\"cache-control\" content=\"" + constants.StandardCacheControl + "\">", +// } +// +// meta := &Meta{ +// Language: "en", +// } +// +// dataset := &Dataset{ +// Mnemonic: appID, +// Tags: tags, +// Meta: meta, +// } +// +// return dataset +// +//} +// +//type Meta struct { +// Language string +//} +// +//type Resources struct { +// Script string +// Style string +//} +// +//type Tags struct { +// Config string +// WebManifest string +// Favicon string +// Script string +// Style string +// Cache string +//} +// +//type Dataset struct { +// Mnemonic string +// *Tags +// *Meta +// *Resources +//} diff --git a/application/source/watch/hashsum.go b/application/source/watch/hashsum.go index 27dc92563c4f6a9487938558633ca0cddf3d92a6..78c3d71f1d432cac3e115b1bd03a1eb13a3dc128 100644 --- a/application/source/watch/hashsum.go +++ b/application/source/watch/hashsum.go @@ -1,102 +1,103 @@ package watch -import ( - "crypto/md5" - "encoding/hex" - "io" - "os" - "sync" - "time" -) - -type FileHash struct { - Name string - Hash string - expiresAt int64 -} - -var ( - fileHashCache map[string]FileHash - fileHashMutex *sync.Mutex -) - -func init() { - fileHashCache = make(map[string]FileHash) - fileHashMutex = &sync.Mutex{} - - go func() { - for { - time.Sleep(time.Minute * 60 * 24) // 1 day - fileHashMutex.Lock() - for k, v := range fileHashCache { - if v.expiresAt < time.Now().Unix() { - delete(fileHashCache, k) - } - } - fileHashMutex.Unlock() - } - }() - -} - -func RemoveFileHash(path string) { - fileHashMutex.Lock() - defer fileHashMutex.Unlock() - - if _, ok := fileHashCache[path]; ok { - delete(fileHashCache, path) - } - -} - -func GetFileHash(path string) string { - fileHashMutex.Lock() - defer fileHashMutex.Unlock() - - if hash, ok := fileHashCache[path]; ok { - return hash.Hash - } - - h, err := buildHash(path) - if err != nil { - return "" - } - - fileHashCache[path] = h - - return h.Hash -} - -type FileHashes map[string]FileHash - -func buildHash(path string) (FileHash, error) { - var h FileHash // HASH - - h.Name = path - h.Hash, _ = hashFile(path) - h.expiresAt = time.Now().Unix() + 3600*24 // 1 day - return h, nil -} - -func hashFile(path string) (string, error) { - var h string // HASH - - file, err := os.Open(path) - if err != nil { - return h, err - } - - defer file.Close() - - hash := md5.New() - - if _, err := io.Copy(hash, file); err != nil { - return h, err - } - - hashInBytes := hash.Sum(nil)[:16] - h = hex.EncodeToString(hashInBytes) - - return h, nil - -} +// +//import ( +// "crypto/md5" +// "encoding/hex" +// "io" +// "os" +// "sync" +// "time" +//) +// +//type FileHash struct { +// Name string +// Hash string +// expiresAt int64 +//} +// +//var ( +// fileHashCache map[string]FileHash +// fileHashMutex *sync.Mutex +//) +// +//func init() { +// fileHashCache = make(map[string]FileHash) +// fileHashMutex = &sync.Mutex{} +// +// go func() { +// for { +// time.Sleep(time.Minute * 60 * 24) // 1 day +// fileHashMutex.Lock() +// for k, v := range fileHashCache { +// if v.expiresAt < time.Now().Unix() { +// delete(fileHashCache, k) +// } +// } +// fileHashMutex.Unlock() +// } +// }() +// +//} +// +//func RemoveFileHash(path string) { +// fileHashMutex.Lock() +// defer fileHashMutex.Unlock() +// +// if _, ok := fileHashCache[path]; ok { +// delete(fileHashCache, path) +// } +// +//} +// +//func GetFileHash(path string) string { +// fileHashMutex.Lock() +// defer fileHashMutex.Unlock() +// +// if hash, ok := fileHashCache[path]; ok { +// return hash.Hash +// } +// +// h, err := buildHash(path) +// if err != nil { +// return "" +// } +// +// fileHashCache[path] = h +// +// return h.Hash +//} +// +//type FileHashes map[string]FileHash +// +//func buildHash(path string) (FileHash, error) { +// var h FileHash // HASH +// +// h.Name = path +// h.Hash, _ = hashFile(path) +// h.expiresAt = time.Now().Unix() + 3600*24 // 1 day +// return h, nil +//} +// +//func hashFile(path string) (string, error) { +// var h string // HASH +// +// file, err := os.Open(path) +// if err != nil { +// return h, err +// } +// +// defer file.Close() +// +// hash := md5.New() +// +// if _, err := io.Copy(hash, file); err != nil { +// return h, err +// } +// +// hashInBytes := hash.Sum(nil)[:16] +// h = hex.EncodeToString(hashInBytes) +// +// return h, nil +// +//} diff --git a/application/source/watch/resources.go b/application/source/watch/resources.go index 69539821e64f22a7eb4110d612611beaab765a96..804099dc76001f0aa8ed4e32d58a75aa0ce2c8a1 100644 --- a/application/source/watch/resources.go +++ b/application/source/watch/resources.go @@ -2,6 +2,7 @@ package watch import ( "bytes" + "github.com/Masterminds/sprig/v3" "github.com/bitfield/script" "github.com/fsnotify/fsnotify" "gitlab.schukai.com/oss/utilities/conan/configuration" @@ -68,13 +69,17 @@ func executeWatchAction(watchPath string) { if w.Command == "" { logging.LogDebug("watching: no command defined for %s", watchPath) + continue + } + + if w.Command == "!reload" { websocket.SendReloadMessage() continue } logging.LogDebug("watching: execute watch action: %s", w.Command) - t, err := template.New("command").Parse(w.Command) + t, err := template.New("").Funcs(sprig.FuncMap()).Parse(w.Command) if err != nil { logging.LogError("watching: execute watch action error: %v", err.Error()) continue @@ -83,6 +88,7 @@ func executeWatchAction(watchPath string) { data := make(map[string]interface{}) data["Path"] = watchPath data["WebPath"] = configuration.GetServerWebPath() + data["ConfigPath"] = configuration.GetConfigurationPath() data["PID"] = os.Getpid() data["Bin"] = os.Args[0] data["Call"] = strings.Join(os.Args[0:], " ") @@ -116,7 +122,7 @@ func executeWatchAction(watchPath string) { } r, err := result.String() - logging.LogDebug("%s", r) + logging.LogInfo("%s", r) if err != nil { logging.LogError("watching: execute watch action error: %v", err.Error()) @@ -144,7 +150,7 @@ func StartWatching() error { if event.Op&fsnotify.Chmod == fsnotify.Chmod { logging.LogDebug("watching: chmod file: %s", d) - RemoveFileHash(fullPath) + //RemoveFileHash(fullPath) } if event.Op&fsnotify.Write == fsnotify.Write { @@ -155,7 +161,7 @@ func StartWatching() error { continue } - RemoveFileHash(fullPath) + //RemoveFileHash(fullPath) executeWatchAction(fullPath) } @@ -168,13 +174,13 @@ func StartWatching() error { if event.Op&fsnotify.Remove == fsnotify.Remove { logging.LogDebug("watching: removed file: %s", d) removeFromWatchlist(fullPath) - RemoveFileHash(fullPath) + //RemoveFileHash(fullPath) } if event.Op&fsnotify.Rename == fsnotify.Rename { logging.LogDebug("watching: renamed file: %s", event.Name) removeFromWatchlist(fullPath) - RemoveFileHash(fullPath) + //RemoveFileHash(fullPath) } case err, ok := <-watcher.Errors: @@ -197,7 +203,8 @@ func InitWatch() { watchList := configuration.GetWatch() if len(watchList) == 0 { watchList = append(watchList, configuration.Watch{ - Path: configuration.GetServerWebPath(), + Path: configuration.GetServerWebPath(), + Command: "!reload", }) } diff --git a/release.json b/release.json index 0f113bc2f7f30c4368b2442b2c2d0efeb0c05cb4..84184c0d86b9da047d3765dcef2cf7d4d6f3646f 100644 --- a/release.json +++ b/release.json @@ -1 +1 @@ -{"version":"1.0.1"} +{"version":"1.0.2"}