Skip to content

Commit fc21e18

Browse files
committed
fix: example refactored
1 parent 4ea5e3f commit fc21e18

2 files changed

Lines changed: 22 additions & 30 deletions

File tree

examples/s3.go

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ func main() {
1414
}
1515

1616
config := map[string]string{
17-
"bucketname": "test.storage",
18-
"Endpoint": "127.0.0.1:9000",
19-
"AccessKey": "minio",
20-
"SecretAccessKey": "minio123",
21-
"SessionToken": "",
22-
"Region": "",
23-
"SSLEnabled": "false",
17+
"bucketname": "test.storage",
18+
"endpoint": "127.0.0.1:9000",
19+
"accessKey": "minio",
20+
"secretkey": "minio123",
21+
"token": "",
22+
"region": "",
23+
"sslenabled": "false",
2424
}
2525
err = s.SetConfig(config)
2626
if err != nil {
@@ -36,22 +36,13 @@ func main() {
3636

3737
err = s.Start()
3838
defer s.Close()
39-
40-
go func() {
41-
for v := range s.GetEvents() {
39+
for {
40+
select {
41+
case v := <-s.GetEvents():
4242
fmt.Printf("EVENT: %s %s\n", v.Key, v.TypeString())
43-
}
44-
fmt.Println("exiting events")
45-
}()
4643

47-
go func() {
48-
for e := range s.GetErrors() {
44+
case e := <-s.GetErrors():
4945
fmt.Printf("ERROR: %#v\n", e)
5046
}
51-
fmt.Println("exiting errors")
52-
}()
53-
54-
time.Sleep(10*time.Second)
55-
s.Close()
56-
time.Sleep(20*time.Second)
47+
}
5748
}

s3.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
type Bool bool
16+
1617
func (bit *Bool) UnmarshalJSON(b []byte) error {
1718
txt := string(b)
1819
*bit = Bool(txt == "1" || txt == "true")
@@ -21,13 +22,13 @@ func (bit *Bool) UnmarshalJSON(b []byte) error {
2122

2223
type objectInfo = minio.ObjectInfo
2324
type S3Configuration struct {
24-
BucketName string
25-
Endpoint string
26-
AccessKey string
27-
SecretAccessKey string
28-
SessionToken string
29-
Region string
30-
SSLEnabled Bool
25+
BucketName string `json:"bucketname"`
26+
Endpoint string `json:"endpoint"`
27+
AccessKey string `json:"accesskey"`
28+
SecretAccessKey string `json:"secretkey"`
29+
SessionToken string `json:"token"`
30+
Region string `json:"region"`
31+
SSLEnabled Bool `json:"sslenabled"`
3132
}
3233

3334
type S3Watcher struct {
@@ -57,8 +58,8 @@ func newS3Watcher(dir string, interval time.Duration) (Watcher, error) {
5758
config: nil,
5859
stop: make(chan bool, 1),
5960
WatcherBase: WatcherBase{
60-
Events: make(chan Event, 100),
61-
Errors: make(chan error, 100),
61+
Events: make(chan Event, 100),
62+
Errors: make(chan error, 100),
6263
watchDir: dir,
6364
pollingTime: interval,
6465
},

0 commit comments

Comments
 (0)