Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the coding style warning which report by golint and revive #131

Merged
merged 67 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
2c7aa65
golint warning fixes
haoel Jul 16, 2021
28d1821
Added the comments for exported functions and variables
haoel Jul 16, 2021
84000a6
Merge branch 'main' into comments
haoel Jul 16, 2021
8601b62
Update pkg/supervisor/object.go
haoel Jul 16, 2021
a48123c
Update pkg/util/sem/semaphore.go
haoel Jul 16, 2021
4d08903
Update pkg/api/api.go
haoel Jul 16, 2021
5d58d0f
Update pkg/common/callback.go
haoel Jul 16, 2021
feb012c
Update pkg/cluster/syncer.go
haoel Jul 16, 2021
11e1e1b
Update pkg/common/callback.go
haoel Jul 16, 2021
895be3a
Update pkg/common/option.go
haoel Jul 16, 2021
4e00b93
Update pkg/util/jmxtool/jmx_controller.go
haoel Jul 16, 2021
6b4f839
Update pkg/util/sem/semaphore.go
haoel Jul 16, 2021
d841985
Update pkg/util/sem/semaphore.go
haoel Jul 16, 2021
cab62a8
Update pkg/common/stat_aggregator.go
haoel Jul 16, 2021
3dc0d10
Update pkg/object/meshcontroller/spec/spec.go
haoel Jul 16, 2021
0631460
Update pkg/object/meshcontroller/spec/spec.go
haoel Jul 16, 2021
f732995
Update pkg/common/callback.go
haoel Jul 16, 2021
b57549d
Update pkg/common/callback.go
haoel Jul 16, 2021
d22700e
Update pkg/common/callback.go
haoel Jul 16, 2021
522d076
Update pkg/common/callback.go
haoel Jul 16, 2021
8e26b32
Update pkg/common/callback.go
haoel Jul 16, 2021
3e30650
Update pkg/common/option.go
haoel Jul 16, 2021
ce1219e
Update pkg/object/meshcontroller/spec/spec.go
haoel Jul 16, 2021
4b09e7b
Update pkg/common/lazybuf.go
haoel Jul 16, 2021
b9f3ac4
Update pkg/common/option.go
haoel Jul 16, 2021
2bc2788
Update pkg/common/option.go
haoel Jul 16, 2021
49d1e28
Update pkg/common/option.go
haoel Jul 16, 2021
5febbce
Update pkg/common/option.go
haoel Jul 16, 2021
7fca965
Update pkg/object/meshcontroller/registrycenter/registry.go
haoel Jul 16, 2021
13003c9
Update pkg/common/option.go
haoel Jul 16, 2021
83bc498
Update pkg/common/option.go
haoel Jul 16, 2021
9faf797
Update pkg/object/meshcontroller/label/label.go
haoel Jul 16, 2021
00a6fa7
Update pkg/common/option.go
haoel Jul 16, 2021
7c4a7e4
Update pkg/common/stat_aggregator.go
haoel Jul 16, 2021
a26a227
Update pkg/common/stat_aggregator.go
haoel Jul 16, 2021
f31a3c8
Update pkg/common/stat_aggregator.go
haoel Jul 16, 2021
ce4a403
Update pkg/common/stat_aggregator.go
haoel Jul 16, 2021
9e82f62
Update pkg/common/lazybuf.go
haoel Jul 16, 2021
3069211
Update pkg/common/lazybuf.go
haoel Jul 16, 2021
b289cf1
Update pkg/common/option.go
haoel Jul 16, 2021
0ecc95e
Update pkg/common/sys_proc_others.go
haoel Jul 16, 2021
f200c1a
Update pkg/filter/retryer/retryer.go
haoel Jul 16, 2021
0aa3cf5
Update pkg/object/function/spec/function.go
haoel Jul 16, 2021
037a84d
Update pkg/object/httppipeline/spec.go
haoel Jul 16, 2021
847c12c
Update pkg/object/ingresscontroller/ingresscontroller.go
haoel Jul 16, 2021
68df3e3
Update pkg/object/ingresscontroller/ingresscontroller.go
haoel Jul 16, 2021
3039ba7
Update pkg/object/meshcontroller/label/label.go
haoel Jul 16, 2021
6c3608b
Update pkg/object/meshcontroller/service/service.go
haoel Jul 16, 2021
09b9dde
Update pkg/object/meshcontroller/service/service.go
haoel Jul 16, 2021
fbfc759
Update pkg/object/meshcontroller/service/service.go
haoel Jul 16, 2021
15cb10a
Update pkg/object/trafficcontroller/trafficcontroller.go
haoel Jul 16, 2021
828f151
Update pkg/object/meshcontroller/service/service.go
haoel Jul 16, 2021
158d223
Update pkg/object/meshcontroller/service/service.go
haoel Jul 16, 2021
824ac3b
Update pkg/object/meshcontroller/service/service.go
haoel Jul 16, 2021
1576fd1
Update pkg/object/meshcontroller/spec/spec.go
haoel Jul 16, 2021
beceaeb
Update pkg/object/trafficcontroller/trafficcontroller.go
haoel Jul 16, 2021
b7f6a1a
Update pkg/object/trafficcontroller/trafficcontroller.go
haoel Jul 16, 2021
87f91c9
Update pkg/object/trafficcontroller/trafficcontroller.go
haoel Jul 16, 2021
360165c
Update pkg/supervisor/object.go
haoel Jul 16, 2021
667e5f8
Update pkg/util/jmxtool/agent_controller.go
haoel Jul 16, 2021
adce6e3
Update pkg/util/jmxtool/jmx_controller.go
haoel Jul 16, 2021
76bdf6f
Update pkg/object/function/spec/function.go
haoel Jul 16, 2021
f3ac7c0
Apply suggestions from code review
haoel Jul 17, 2021
f69dcc5
change the function name from `NewAPIServer` to `newAPIServer`
haoel Jul 17, 2021
92b0856
typo: `synRaw` ==> `syncRaw`
haoel Jul 17, 2021
eacdc2b
rename: `api.APIErr`-> `api.Err`, `api.APIGroup` -> `api.Group`, `api…
haoel Jul 17, 2021
5975d52
fix the coding style warning reported by revive
haoel Jul 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions example/backend-service/mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import (
"time"
)

// TeeWriter is a io.Writer wapper
type TeeWriter struct {
writers []io.Writer
}

// NewTeeWriter function return a TeeWriter
func NewTeeWriter(writers ...io.Writer) *TeeWriter {
return &TeeWriter{writers: writers}
}

// Write function write the data
func (tw *TeeWriter) Write(p []byte) (n int, err error) {
for _, w := range tw.writers {
w.Write(p)
Expand Down
1 change: 1 addition & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func RegisterAPIs(apiGroup *APIGroup) {
apisChangeChan <- struct{}{}
}

// UnregisterAPIs unregisters the API group
func UnregisterAPIs(group string) {
apisMutex.Lock()
defer apisMutex.Unlock()
Expand Down
1 change: 1 addition & 0 deletions pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type (
mutexMutex sync.Mutex
}

// APIGroup is the API group
APIGroup struct {
Group string
Entries []*APIEntry
Expand Down
5 changes: 5 additions & 0 deletions pkg/cluster/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (s *Syncer) run(key string, prefix bool, send func(data map[string]*mvccpb.
}
}

// Sync syncs a given Etcd key's value through the returned channel.
func (s *Syncer) Sync(key string) (<-chan *string, error) {
ch := make(chan *string, 10)

Expand All @@ -191,6 +192,7 @@ func (s *Syncer) Sync(key string) (<-chan *string, error) {
return ch, nil
}

// SynRaw syncs a given Etcd key's raw Etcd mvccpb structure through the returned channel.
func (s *Syncer) SyncRaw(key string) (<-chan *mvccpb.KeyValue, error) {
ch := make(chan *mvccpb.KeyValue, 10)

Expand All @@ -206,6 +208,7 @@ func (s *Syncer) SyncRaw(key string) (<-chan *mvccpb.KeyValue, error) {
return ch, nil
}

// SyncPrefix syncs Etcd keys' values with the same prefix through the returned channel.
func (s *Syncer) SyncPrefix(prefix string) (<-chan map[string]string, error) {
ch := make(chan map[string]string, 10)

Expand All @@ -225,6 +228,7 @@ func (s *Syncer) SyncPrefix(prefix string) (<-chan map[string]string, error) {
return ch, nil
}

// SyncRawPrefix syncs Etcd keys' values with the same prefix in raw Etcd mvccpb structure format through the returned channel.
func (s *Syncer) SyncRawPrefix(prefix string) (<-chan map[string]*mvccpb.KeyValue, error) {
ch := make(chan map[string]*mvccpb.KeyValue, 10)

Expand All @@ -245,6 +249,7 @@ func (s *Syncer) SyncRawPrefix(prefix string) (<-chan map[string]*mvccpb.KeyValu
return ch, nil
}

// Close closes the syncer
func (s *Syncer) Close() {
close(s.done)
}
18 changes: 15 additions & 3 deletions pkg/common/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,40 @@
package common

const (
// CallbacksInitCapacity is the capacity of callback
CallbacksInitCapacity = 20

NormalPriorityCallback = "__NoRmAl_PrIoRiTy_CaLlBaCk"
// NormalPriorityCallback is the name of normal priority callback
NormalPriorityCallback = "__NoRmAl_PrIoRiTy_CaLlBaCk"
// CriticalPriorityCallback is the name of critical priority callback
CriticalPriorityCallback = "__CrItIcAl_PrIoRiTy_CaLlBaCk"
)

////

// NamedCallback is the named callback struct
type NamedCallback struct {
name string
callback interface{}
}

// NewNamedCallback return a new named callback
func NewNamedCallback(name string, callback interface{}) *NamedCallback {
return &NamedCallback{
name: name,
callback: callback,
}
}

// Name returns callback name
func (cb *NamedCallback) Name() string {
return cb.name
}

// Callback returns callback function
func (cb *NamedCallback) Callback() interface{} {
return cb.callback
}

// SetCallback sets the callback function
func (cb *NamedCallback) SetCallback(callback interface{}) interface{} {
oriCallback := cb.callback
cb.callback = callback
Expand All @@ -57,32 +63,37 @@ type namedCallbackWithIdx struct {
idxOfOrder int
}

// NamedCallbackSet is a set of NamedCallback
type NamedCallbackSet struct {
// critical callback takes low index, normal callback takes high index
callbacks []*NamedCallback // index for access by order
names map[string]*namedCallbackWithIdx // index for access by callback constant

}

// NewNamedCallbackSet returns a new NamedCallbackSet
func NewNamedCallbackSet() *NamedCallbackSet {
return &NamedCallbackSet{
names: make(map[string]*namedCallbackWithIdx, CallbacksInitCapacity),
callbacks: make([]*NamedCallback, 0, CallbacksInitCapacity),
}
}

// CopyCallbacks copies the current callbacks
func (cbs *NamedCallbackSet) CopyCallbacks() []*NamedCallback {
ret := make([]*NamedCallback, len(cbs.callbacks))
copy(ret, cbs.callbacks)
return ret
}

// GetCallbacks get callbacks
func (cbs *NamedCallbackSet) GetCallbacks() []*NamedCallback {
return cbs.callbacks
}

////

// AddCallback adds a callback into a callback set with priority
func AddCallback(cbs *NamedCallbackSet, name string, callback interface{}, priority string) *NamedCallbackSet {
if cbs == nil {
return nil
Expand Down Expand Up @@ -123,6 +134,7 @@ func AddCallback(cbs *NamedCallbackSet, name string, callback interface{}, prior
return cbs
}

// DeleteCallback deletes a callback in callback set
func DeleteCallback(cbs *NamedCallbackSet, name string) *NamedCallbackSet {
if cbs == nil {
return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/common/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strings"
)

// GoID returns goroutine ID
func GoID() (int, error) {
var buf [64]byte
n := runtime.Stack(buf[:], false)
Expand All @@ -36,6 +37,7 @@ func GoID() (int, error) {
return id, nil
}

// CloseChan closes a channel
func CloseChan(c interface{}) (ret bool) {
val := reflect.ValueOf(c)
if val.IsNil() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/common/lazybuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ type Lazybuf struct {
w int
}

// NewLazybuf returns lazy buffer
func NewLazybuf(s string) *Lazybuf {
return &Lazybuf{
s: s,
}
}

// Index returns a byte by its index
func (b *Lazybuf) Index(i int) byte {
if b.buf != nil {
return b.buf[i]
}
return b.s[i]
}

// Append appends a byte into buffer
func (b *Lazybuf) Append(c byte) {
if b.buf == nil {
if b.w < len(b.s) && b.s[b.w] == c {
Expand All @@ -55,6 +58,7 @@ func (b *Lazybuf) Append(c byte) {
b.w++
}

// String returns the string of lazybuf
func (b *Lazybuf) String() string {
if b.buf == nil {
return b.s[:b.w]
Expand Down
Loading