From 3c697abd5b5a4f611e8d6cb2629a405ee6425ba1 Mon Sep 17 00:00:00 2001 From: Daniel <dhaavi@users.noreply.github.com> Date: Wed, 28 Sep 2022 22:37:54 +0200 Subject: [PATCH] Fix linter errors --- container/doc.go | 29 ++++++----- database/doc.go | 83 ++++++++++++++++---------------- database/query/parser.go | 1 + modules/mgmt.go | 13 +++-- modules/subsystems/registry.go | 10 ++-- notifications/doc.go | 27 +++++------ runtime/singe_record_provider.go | 21 ++++---- utils/onceagain.go | 8 +-- utils/stablepool.go | 1 - 9 files changed, 95 insertions(+), 98 deletions(-) diff --git a/container/doc.go b/container/doc.go index 16fd161..76cc73c 100644 --- a/container/doc.go +++ b/container/doc.go @@ -5,23 +5,22 @@ // Byte slices added to the Container are not changed or appended, to not corrupt any other data that may be before and after the given slice. // If interested, consider the following example to understand why this is important: // -// package main +// package main // -// import ( -// "fmt" -// ) +// import ( +// "fmt" +// ) // -// func main() { -// a := []byte{0, 1,2,3,4,5,6,7,8,9} -// fmt.Printf("a: %+v\n", a) -// fmt.Printf("\nmaking changes...\n(we are not changing a directly)\n\n") -// b := a[2:6] -// c := append(b, 10, 11) -// fmt.Printf("b: %+v\n", b) -// fmt.Printf("c: %+v\n", c) -// fmt.Printf("a: %+v\n", a) -// } +// func main() { +// a := []byte{0, 1,2,3,4,5,6,7,8,9} +// fmt.Printf("a: %+v\n", a) +// fmt.Printf("\nmaking changes...\n(we are not changing a directly)\n\n") +// b := a[2:6] +// c := append(b, 10, 11) +// fmt.Printf("b: %+v\n", b) +// fmt.Printf("c: %+v\n", c) +// fmt.Printf("a: %+v\n", a) +// } // // run it here: https://play.golang.org/p/xu1BXT3QYeE -// package container diff --git a/database/doc.go b/database/doc.go index 3c8ff8b..1e1e6a5 100644 --- a/database/doc.go +++ b/database/doc.go @@ -1,63 +1,62 @@ /* Package database provides a universal interface for interacting with the database. -A Lazy Database +# A Lazy Database The database system can handle Go structs as well as serialized data by the dsd package. While data is in transit within the system, it does not know which form it currently has. Only when it reaches its destination, it must ensure that it is either of a certain type or dump it. -Record Interface +# Record Interface The database system uses the Record interface to transparently handle all types of structs that get saved in the database. Structs include the Base struct to fulfill most parts of the Record interface. Boilerplate Code: - type Example struct { - record.Base - sync.Mutex + type Example struct { + record.Base + sync.Mutex - Name string - Score int - } + Name string + Score int + } - var ( - db = database.NewInterface(nil) - ) + var ( + db = database.NewInterface(nil) + ) - // GetExample gets an Example from the database. - func GetExample(key string) (*Example, error) { - r, err := db.Get(key) - if err != nil { - return nil, err - } + // GetExample gets an Example from the database. + func GetExample(key string) (*Example, error) { + r, err := db.Get(key) + if err != nil { + return nil, err + } - // unwrap - if r.IsWrapped() { - // only allocate a new struct, if we need it - new := &Example{} - err = record.Unwrap(r, new) - if err != nil { - return nil, err - } - return new, nil - } + // unwrap + if r.IsWrapped() { + // only allocate a new struct, if we need it + new := &Example{} + err = record.Unwrap(r, new) + if err != nil { + return nil, err + } + return new, nil + } - // or adjust type - new, ok := r.(*Example) - if !ok { - return nil, fmt.Errorf("record not of type *Example, but %T", r) - } - return new, nil - } + // or adjust type + new, ok := r.(*Example) + if !ok { + return nil, fmt.Errorf("record not of type *Example, but %T", r) + } + return new, nil + } - func (e *Example) Save() error { - return db.Put(e) - } - - func (e *Example) SaveAs(key string) error { - e.SetKey(key) - return db.PutNew(e) - } + func (e *Example) Save() error { + return db.Put(e) + } + func (e *Example) SaveAs(key string) error { + e.SetKey(key) + return db.PutNew(e) + } */ package database diff --git a/database/query/parser.go b/database/query/parser.go index 988ea59..b6abd39 100644 --- a/database/query/parser.go +++ b/database/query/parser.go @@ -14,6 +14,7 @@ type snippet struct { } // ParseQuery parses a plaintext query. Special characters (that must be escaped with a '\') are: `\()` and any whitespaces. +// //nolint:gocognit func ParseQuery(query string) (*Query, error) { snippets, err := extractSnippets(query) diff --git a/modules/mgmt.go b/modules/mgmt.go index adb460d..7bacddb 100644 --- a/modules/mgmt.go +++ b/modules/mgmt.go @@ -55,14 +55,13 @@ func (m *Module) EnabledAsDependency() bool { // // Example: // -// EnableModuleManagement(func(m *modules.Module) { -// // some module has changed ... -// // do what ever you like -// -// // Run the built-in module management -// modules.ManageModules() -// }) +// EnableModuleManagement(func(m *modules.Module) { +// // some module has changed ... +// // do what ever you like // +// // Run the built-in module management +// modules.ManageModules() +// }) func EnableModuleManagement(changeNotifyFn func(*Module)) bool { if moduleMgmtEnabled.SetToIf(false, true) { modulesChangeNotifyFn = changeNotifyFn diff --git a/modules/subsystems/registry.go b/modules/subsystems/registry.go index 2914243..50b472f 100644 --- a/modules/subsystems/registry.go +++ b/modules/subsystems/registry.go @@ -125,11 +125,11 @@ func (mng *Manager) Get(keyOrPrefix string) ([]record.Record, error) { // you. Pass a nil option to force enable. // // TODO(ppacher): IMHO the subsystem package is not responsible of registering -// the "toggle option". This would also remove runtime -// dependency to the config package. Users should either pass -// the BoolOptionFunc and the expertise/release level directly -// or just pass the configuration key so those information can -// be looked up by the registry. +// the "toggle option". This would also remove runtime +// dependency to the config package. Users should either pass +// the BoolOptionFunc and the expertise/release level directly +// or just pass the configuration key so those information can +// be looked up by the registry. func (mng *Manager) Register(id, name, description string, module *modules.Module, configKeySpace string, option *config.Option) error { mng.l.Lock() defer mng.l.Unlock() diff --git a/notifications/doc.go b/notifications/doc.go index 29c3b53..be18386 100644 --- a/notifications/doc.go +++ b/notifications/doc.go @@ -1,7 +1,7 @@ /* Package notifications provides a notification system. -Notification Lifecycle +# Notification Lifecycle 1. Create Notification with an ID and Message. 2. Set possible actions and save it. @@ -9,19 +9,18 @@ Notification Lifecycle Example - // create notification - n := notifications.New("update-available", "A new update is available. Restart to upgrade.") - // set actions and save - n.AddAction("later", "Later").AddAction("restart", "Restart now!").Save() - - // wait for user action - selectedAction := <-n.Response() - switch selectedAction { - case "later": - log.Infof("user wants to upgrade later.") - case "restart": - log.Infof("user wants to restart now.") - } + // create notification + n := notifications.New("update-available", "A new update is available. Restart to upgrade.") + // set actions and save + n.AddAction("later", "Later").AddAction("restart", "Restart now!").Save() + // wait for user action + selectedAction := <-n.Response() + switch selectedAction { + case "later": + log.Infof("user wants to upgrade later.") + case "restart": + log.Infof("user wants to restart now.") + } */ package notifications diff --git a/runtime/singe_record_provider.go b/runtime/singe_record_provider.go index 6f232b5..c941f58 100644 --- a/runtime/singe_record_provider.go +++ b/runtime/singe_record_provider.go @@ -15,17 +15,16 @@ type singleRecordReader struct { // // Example: // -// type MyValue struct { -// record.Base -// Value string -// } -// r := new(MyValue) -// pushUpdate, _ := runtime.Register("my/key", ProvideRecord(r)) -// r.Lock() -// r.Value = "foobar" -// pushUpdate(r) -// r.Unlock() -// +// type MyValue struct { +// record.Base +// Value string +// } +// r := new(MyValue) +// pushUpdate, _ := runtime.Register("my/key", ProvideRecord(r)) +// r.Lock() +// r.Value = "foobar" +// pushUpdate(r) +// r.Unlock() func ProvideRecord(r record.Record) ValueProvider { return &singleRecordReader{r} } diff --git a/utils/onceagain.go b/utils/onceagain.go index 0d34622..78802b1 100644 --- a/utils/onceagain.go +++ b/utils/onceagain.go @@ -24,7 +24,9 @@ type OnceAgain struct { // Do calls the function f if and only if Do is being called for the // first time for this instance of Once. In other words, given -// var once Once +// +// var once Once +// // if once.Do(f) is called multiple times, only the first call will invoke f, // even if f has a different value in each invocation. A new instance of // Once is required for each function to execute. @@ -32,14 +34,14 @@ type OnceAgain struct { // Do is intended for initialization that must be run exactly once. Since f // is niladic, it may be necessary to use a function literal to capture the // arguments to a function to be invoked by Do: -// config.once.Do(func() { config.init(filename) }) +// +// config.once.Do(func() { config.init(filename) }) // // Because no call to Do returns until the one call to f returns, if f causes // Do to be called, it will deadlock. // // If f panics, Do considers it to have returned; future calls of Do return // without calling f. -// func (o *OnceAgain) Do(f func()) { // Note: Here is an incorrect implementation of Do: // diff --git a/utils/stablepool.go b/utils/stablepool.go index d253d65..5195b44 100644 --- a/utils/stablepool.go +++ b/utils/stablepool.go @@ -9,7 +9,6 @@ import "sync" // A StablePool is a set of temporary objects that may be individually saved and // retrieved. // -// // In contrast to sync.Pool, items are not removed automatically. Every item // will be returned at some point. Items are returned in a FIFO manner in order // to evenly distribute usage of a set of items.