-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
175 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package config | ||
|
||
// Config 返回配置 | ||
type Config struct { | ||
Content []byte | ||
ContentMD5 string | ||
Pulled bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package aliacm | ||
|
||
import "github.com/xiaojiaoyu100/aliyun-acm/v2/info" | ||
|
||
// Hook 提供了长轮询失败发生的回调 | ||
type Hook func(unit Unit, err error) | ||
type Hook func(i info.Info, err error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package info | ||
|
||
type Info struct { | ||
Group string | ||
DataID string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package observer | ||
|
||
import ( | ||
"github.com/xiaojiaoyu100/aliyun-acm/v2/config" | ||
"github.com/xiaojiaoyu100/aliyun-acm/v2/info" | ||
) | ||
|
||
type Handler func(coll map[info.Info]*config.Config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package observer | ||
|
||
import ( | ||
"github.com/xiaojiaoyu100/aliyun-acm/v2/config" | ||
"github.com/xiaojiaoyu100/aliyun-acm/v2/info" | ||
) | ||
|
||
type Observer struct { | ||
coll map[info.Info]*config.Config | ||
h Handler | ||
} | ||
|
||
func New(ss ...Setting) (*Observer, error) { | ||
o := &Observer{} | ||
o.coll = make(map[info.Info]*config.Config) | ||
for _, s := range ss { | ||
if err := s(o); err != nil { | ||
return nil, err | ||
} | ||
} | ||
return o, nil | ||
} | ||
|
||
func (o *Observer) Ready() bool { | ||
var ret = true | ||
for _, c := range o.coll { | ||
if !c.Pulled { | ||
ret = false | ||
break | ||
} | ||
} | ||
return ret | ||
} | ||
|
||
func (o *Observer) Info() []info.Info { | ||
var ii []info.Info | ||
for i, _ := range o.coll { | ||
ii = append(ii, i) | ||
} | ||
return ii | ||
} | ||
|
||
func (o *Observer) Handle() { | ||
o.h(o.coll) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package observer | ||
|
||
import ( | ||
"github.com/xiaojiaoyu100/aliyun-acm/v2/config" | ||
"github.com/xiaojiaoyu100/aliyun-acm/v2/info" | ||
) | ||
|
||
type Setting func(o *Observer) error | ||
|
||
// WithInfo loads info. | ||
func WithInfo(ii ...info.Info) Setting { | ||
return func(o *Observer) error { | ||
for _, i := range ii { | ||
o.coll[i] = &config.Config{} | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithHandler initializes a handler. | ||
func WithHandler(h Handler) Setting { | ||
return func(o *Observer) error { | ||
o.h = h | ||
return nil | ||
} | ||
} |