Skip to content
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
5 changes: 5 additions & 0 deletions Taskfile.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ tasks:
deps:
- lint
- test

demo:
dir: demo-app
cmds:
- go run ./cmd/clock/main.go
38 changes: 38 additions & 0 deletions demo-app/cmd/clock/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"context"
"fmt"
"time"

"github.com/mishankov/platforma/application"
"github.com/mishankov/platforma/log"
)

type Clock struct{}

func (r *Clock) Run(ctx context.Context) error {
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

for {
select {
case <-ticker.C:
log.InfoContext(ctx, "tick")
case <-ctx.Done():
log.InfoContext(ctx, "finished")
return fmt.Errorf("context error: %w", ctx.Err())
}
}
}

func main() {
ctx := context.Background()
app := application.New()

app.RegisterService("clock", &Clock{})

if err := app.Run(ctx); err != nil {
log.ErrorContext(ctx, "app finished with error", "error", err)
}
}
3 changes: 2 additions & 1 deletion log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log/slog"
"os"
)

type logger interface {
Expand All @@ -19,7 +20,7 @@ type logger interface {
ErrorContext(ctx context.Context, msg string, args ...any)
}

var Logger logger = slog.Default() //nolint:gochecknoglobals
var Logger logger = New(os.Stdout, "text", slog.LevelInfo, nil) //nolint:gochecknoglobals

// SetDefault sets the default logger used by the package-level logging functions.
func SetDefault(l logger) {
Expand Down