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

Add a Go report card, fix lint #271

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading