Skip to content

Commit

Permalink
Merge pull request #271 from thockin/master
Browse files Browse the repository at this point in the history
Add a Go report card, fix lint
  • Loading branch information
pohly authored Feb 20, 2024
2 parents 13ec622 + 3717a4b commit 4392df4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# A minimal logging API for Go

[![Go Reference](https://pkg.go.dev/badge/github.com/go-logr/logr.svg)](https://pkg.go.dev/github.com/go-logr/logr)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-logr/logr)](https://goreportcard.com/report/github.com/go-logr/logr)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/go-logr/logr/badge)](https://securityscorecards.dev/viewer/?platform=github.com&org=go-logr&repo=logr)

logr offers an(other) opinion on how Go programs and libraries can do logging
Expand Down
4 changes: 2 additions & 2 deletions examples/tab_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ var _ logr.LogSink = &tabLogSink{}

// Note that Init usually takes a pointer so it can modify the receiver to save
// runtime info.
func (_ *tabLogSink) Init(info logr.RuntimeInfo) {
func (*tabLogSink) Init(info logr.RuntimeInfo) {
}

func (_ tabLogSink) Enabled(level int) bool {
func (tabLogSink) Enabled(level int) bool {
return true
}

Expand Down
8 changes: 8 additions & 0 deletions examples/usage_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@ var objectMap = map[string]Object{
},
}

// Object is an app contruct that might want to be logged.
type Object struct {
Name string
Kind string
Details any
}

// Client is a simulated client in this example app.
type Client struct {
objects map[string]Object
log logr.Logger
}

// Get retrieves an object.
func (c *Client) Get(key string) (Object, error) {
c.log.V(1).Info("fetching object", "key", key)
obj, ok := c.objects[key]
Expand All @@ -72,6 +75,7 @@ func (c *Client) Get(key string) (Object, error) {
return obj, nil
}

// Save stores an object.
func (c *Client) Save(obj Object) error {
c.log.V(1).Info("saving object", "key", obj.Name, "object", obj)
if rand.Intn(2) == 0 {
Expand All @@ -81,6 +85,7 @@ func (c *Client) Save(obj Object) error {
return nil
}

// WatchNext waits for object updates.
func (c *Client) WatchNext() string {
time.Sleep(2 * time.Second)

Expand All @@ -98,12 +103,14 @@ func (c *Client) WatchNext() string {
return ""
}

// Controller is the main point of this example.
type Controller struct {
log logr.Logger
expectedKind string
client *Client
}

// Run starts the example controller.
func (c *Controller) Run() {
c.log.Info("starting reconciliation")

Expand Down Expand Up @@ -141,6 +148,7 @@ func (c *Controller) Run() {
c.log.Info("stopping reconciliation")
}

// NewController allocates and initializes a Controller.
func NewController(log logr.Logger, objectKind string) *Controller {
ctrlLogger := log.WithName("controller").WithName(objectKind)
client := &Client{
Expand Down

0 comments on commit 4392df4

Please sign in to comment.