Skip to content

Commit

Permalink
Testing the package stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
justaverylee committed Oct 17, 2020
1 parent f693437 commit 35eaeb2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
20 changes: 11 additions & 9 deletions auth/auth-go-cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func MakeGoCacheStore(filename string) (*GoCacheStore, error) {
// Get gets from the store
func (store GoCacheStore) Get(k string) (*Account, bool) {
account, found := store.cache.Get(k)
if (found) {
if found {
return account.(*Account), found
}
return nil, found
Expand All @@ -81,7 +81,7 @@ func (store GoCacheStore) Save() error {

var accounts []*Account

for _, v := range items {
for _, v := range items {
accounts = append(accounts, v.Object.(*Account))
}

Expand All @@ -102,8 +102,6 @@ func reload(filename string, store *GoCacheStore) error {

var readdata []Account

fmt.Println(data)

jsonerr := json.Unmarshal(data, &readdata)
if jsonerr != nil {
fmt.Println("JsonErr")
Expand All @@ -114,7 +112,7 @@ func reload(filename string, store *GoCacheStore) error {

for _, acc := range readdata {
items[acc.User] = cache.Item{
Object: &acc,
Object: &acc,
Expiration: 0,
}
}
Expand All @@ -127,10 +125,14 @@ func waitForUpdates(watch *fsnotify.Watcher, store *GoCacheStore) {
for {
select {
case e := <-watch.Events:
err := reload(e.Name, store)
if err != nil {
fmt.Println("Error reloading auth")
fmt.Println(e)
if e.Op != fsnotify.Chmod {
err := reload(e.Name, store)
if err != nil {
fmt.Println("Error reloading auth (see below error message)")
fmt.Println(err)
} else {
fmt.Println("Auth file has been updated.")
}
}
case e := <-watch.Errors:
fmt.Println("File watch detected an error, auth may not stay up to date with file! Consider restarting the application")
Expand Down
3 changes: 1 addition & 2 deletions auth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ go 1.15
require (
github.com/fsnotify/fsnotify v1.4.9
github.com/patrickmn/go-cache v2.1.0+incompatible
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
)
18 changes: 18 additions & 0 deletions auth/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/patrickmn/go-cache v1.0.0 h1:3gD5McaYs9CxjyK5AXGcq8gdeCARtd/9gJDUvVeaZ0Y=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/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-20191005200804-aed5e4c7ecf9 h1:L2auWcuQIvxz9xSEqzESnV/QN/gNRXNApHi3fYwl2w0=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2 changes: 2 additions & 0 deletions fileserver/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/zggz/securefileserver/fileserver

go 1.15

require github.com/zggz/securefileserver/auth v0.0.0-20201017040310-f6934374b054
17 changes: 17 additions & 0 deletions fileserver/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/zggz/securefileserver v0.0.0-20201017040310-f6934374b054 h1:X0iRoa3HssXa77GbaooHaPghlOjf2krWhwt2oY7MYvk=
github.com/zggz/securefileserver/auth v0.0.0-20201017040310-f6934374b054 h1:4rlMehK8EqUCGaoAn3WHPBNwBxhLH69e4hd4S15mCpI=
github.com/zggz/securefileserver/auth v0.0.0-20201017040310-f6934374b054/go.mod h1:jMkXLOaBCw6g2gFxVRfH+9GrCDEkrboO2dq+iKAeI4M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/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-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

0 comments on commit 35eaeb2

Please sign in to comment.