Go to file
2025-05-13 18:17:36 +02:00
.github chore: update dependabot 2025-05-04 14:49:56 +02:00
examples refactor: move examples 2025-05-04 14:49:46 +02:00
.editorconfig initial commit 2024-08-01 22:57:38 +02:00
.gitignore initial commit 2024-08-01 22:57:38 +02:00
.golangci.yml feat: bump golangci lint 2025-05-04 14:49:37 +02:00
.goreleaser.yml initial commit 2024-08-01 22:57:38 +02:00
.husky.yaml feat: bump golangci lint 2025-05-04 14:49:37 +02:00
channel.go refactor: use zap 2025-05-13 08:32:38 +02:00
CODE_OF_CONDUCT.md initial commit 2024-08-01 22:57:38 +02:00
context.go refactor: use zap 2025-05-13 08:32:38 +02:00
errors.go initial commit 2024-08-01 22:57:38 +02:00
func.go initial commit 2024-08-01 22:57:38 +02:00
go_test.go fix: linter 2024-08-01 23:01:15 +02:00
go.go fix: completed metric 2025-05-13 18:17:36 +02:00
go.mod refactor: use zap 2025-05-13 08:32:38 +02:00
go.sum refactor: use zap 2025-05-13 08:32:38 +02:00
LICENSE chore: add community files 2025-05-04 14:49:18 +02:00
Makefile initial commit 2024-08-01 22:57:38 +02:00
README.md chore: add community files 2025-05-04 14:49:18 +02:00
value.go fix: lint issues 2025-05-04 14:50:19 +02:00

gofuncy

Build Status Go Report Card godoc goreleaser

Stop using go func, start using gofuncy!

  • ctx as a first class citizen
  • error return as a first class citizen
  • optional: enable telemetry (metrics & traces)
    • gofuncy.routine.count counter
    • gofuncy.routine.duration histogram
    • gofuncy.channel.sent.count counter
    • gofuncy.channel.sent.duration histogram

Configuration

Environment variables:

  • OTEL_ENABLED: enable telemetry
  • GOFUNCY_CHANNEL_VALUE_EVENTS_ENABLED: creates a span event for every value sent into the channel
  • GOFUNCY_CHANNEL_VALUE_ATTRIBUTE_ENABLED: adds the json dump of the data to the span event

Usage

From:

package main

func main() {
  go func() {
    numbers, err := GenerateNumbers(5)
    if err != nil {
      panic(err)
    }
  }()
}

To:

package main

import (
  "github.com/foomo/gofuncy"
)

func main() {
  errChan := gofuncy.Go(func(ctx context.Context) error {
    numbers, err := GenerateNumbers(5)
    return err
  })
  if err := <-errChan; err != nil {
    panic(err)
  }
}

Concept

Routines

Error

Each routine can return an error that is being returned through an error channel:

errChan := gofuncy.Go(func (ctx context.Context) error {
return nil
})

if err := <- errChan; err != nil {
panic(err)
}

Context

Each routine will receive its own base context, which can be set:

errChan := gofuncy.Go(send(msg), gofuncy.WithContext(context.Background()))
flowchart TB
  subgraph root
    channel[Channel]
    subgraph "Routine A"
      ctxA[ctx] --> senderA
      senderA[Sender]
    end
    subgraph "Routine B"
      ctxB[ctx] --> senderB
      senderB[Sender]
    end
    senderA --> channel
    senderB --> channel
    channel --> receiverC
    subgraph "Routine C"
      ctxC[ctx] --> receiverC
      receiverC[Receiver]
    end
  end

Names

Using the context we will inject a name for the process so that it can always be identified:

flowchart TB
  subgraph root
    channel[Channel]
    subgraph "Routine A"
      ctxA[ctx] -- ctx: sender - a --> senderA
      senderA[Sender]
    end
    subgraph "Routine B"
      ctxB[ctx] -- ctx: sender - b --> senderB
      senderB[Sender]
    end
    senderA --> channel
    senderB --> channel
    channel --> receiverC
    subgraph "Routine C"
      ctxC[ctx] -- ctx: receiver - b --> receiverC
      receiverC[Receiver]
    end
  end

Telemetry

Metrics:

Name Type
gofuncy.routine.count UpDownCounter
gofuncy.routine.duration Histogram
flowchart TB
  subgraph root
    subgraph rA ["Routine A"]
      handler[Handler]
    end
    rA -- gofuncy . routine . count --> Metrics
    rA -- gofuncy . routine . duration --> Metrics
    rA -- span: routine - a --> Trace
  end

How to Contribute

Please refer to the CONTRIBUTING details and follow the CODE_OF_CONDUCT and SECURITY guidelines.

License

Distributed under MIT License, please see license file within the code for more details.

Made with ♥ foomo by bestbytes