Skip to content

Commit

Permalink
doc(main): Added documentation (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekkinox committed Jan 29, 2024
1 parent c6b073d commit 6f6da6d
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 4 deletions.
100 changes: 100 additions & 0 deletions docs/modules/fxgenerate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Generate Module

[![ci](https://github.com/ankorstore/yokai/actions/workflows/fxgenerate-ci.yml/badge.svg)](https://github.com/ankorstore/yokai/actions/workflows/fxgenerate-ci.yml)
[![go report](https://goreportcard.com/badge/github.com/ankorstore/yokai/fxgenerate)](https://goreportcard.com/report/github.com/ankorstore/yokai/fxgenerate)
[![codecov](https://codecov.io/gh/ankorstore/yokai/graph/badge.svg?token=ghUBlFsjhR&flag=fxgenerate)](https://app.codecov.io/gh/ankorstore/yokai/tree/main/fxgenerate)
[![Deps](https://img.shields.io/badge/osi-deps-blue)](https://deps.dev/go/github.com%2Fankorstore%2Fyokai%2Ffxgenerate)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/ankorstore/yokai/fxgenerate)](https://pkg.go.dev/github.com/ankorstore/yokai/fxgenerate)

## Overview

Yokai provides a [fxgenerate](https://github.com/ankorstore/yokai/tree/main/fxgenerate) module, allowing your application to generate UUIDs.

It wraps the [generate](https://github.com/ankorstore/yokai/tree/main/generate) module, based on [Google UUID](https://github.com/google/uuid).

## Installation

The [fxgenerate](https://github.com/ankorstore/yokai/tree/main/fxgenerate) module is automatically loaded by
the [fxcore](https://github.com/ankorstore/yokai/tree/main/fxcore).

When you use a Yokai [application template](https://ankorstore.github.io/yokai/applications/templates/), you have nothing to install, it's ready to use.

## Usage

This module makes available the [UuidGenerator](https://github.com/ankorstore/yokai/blob/main/generate/uuid/generator.go) in
Yokai dependency injection system.

It is built on top of `Google UUID`, see its [documentation](https://github.com/google/uuid) for more details about available methods.

To access it, you just need to inject it where needed, for example:

```go title="internal/service/example.go"
package service

import (
"fmt"

"github.com/ankorstore/yokai/generate/uuid"
)

type ExampleService struct {
generator uuid.UuidGenerator
}

func NewExampleService(generator uuid.UuidGenerator) *ExampleService {
return &ExampleService{
generator: generator,
}
}

func (s *ExampleService) DoSomething() {
// uuid: dcb5d8b3-4517-4957-a42c-604d11758561
fmt.Printf("uuid: %s", s.generator.Generate())
}
```

## Testing

This module provides the possibility to make the [UuidGenerator](https://github.com/ankorstore/yokai/blob/main/generate/uuid/generator.go) generate deterministic values (for testing purposes).

For this, you need to:

- first provide the deterministic value to be used for generation, annotated with `name:"generate-test-uuid-value"`
- then override the `UuidGeneratorFactory` with the provided [TestUuidGeneratorFactory](https://github.com/ankorstore/yokai/blob/main/fxgenerate/fxgeneratetest/uuid/factory.go)

```go title="internal/service/example_test.go"
package internal_test

import (
"testing"

"github.com/ankorstore/yokai/fxgenerate/fxgeneratetest/uuid"
"github.com/foo/bar/internal"
"github.com/foo/bar/internal/service"
"github.com/stretchr/testify/assert"
"go.uber.org/fx"
)

func TestExampleServiceDoSomething(t *testing.T) {
var exampleService *service.ExampleService

internal.RunTest(
t,
fx.Populate(&exampleService),
// provide and annotate the deterministic value
fx.Provide(
fx.Annotate(
func() string {
return "some value"
},
fx.ResultTags(`name:"generate-test-uuid-value"`),
),
),
// override the UuidGeneratorFactory with the TestUuidGeneratorFactory
fx.Decorate(uuid.NewFxTestUuidGeneratorFactory),
)

//assertion
assert.Equal(t, "uuid: some value", exampleService.DoSomething())
}
```
3 changes: 2 additions & 1 deletion docs/modules/fxhealthcheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ When you use a Yokai [application template](https://ankorstore.github.io/yokai/a

## Usage

This module will enable Yokai to collect registered [CheckerProbe](https://github.com/ankorstore/yokai/blob/main/healthcheck/probe.go) implementations, and make available to the [Checker](https://github.com/ankorstore/yokai/blob/main/healthcheck/checker.go) in
This module will enable Yokai to collect registered [CheckerProbe](https://github.com/ankorstore/yokai/blob/main/healthcheck/probe.go) implementations, and make them available to the [Checker](https://github.com/ankorstore/yokai/blob/main/healthcheck/checker.go) in
its dependency injection system.

You can register probes for `startup`, `liveness` and / or `readiness` [checks](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).
Expand Down Expand Up @@ -110,6 +110,7 @@ func ProvideServices() fx.Option {
fxhealthcheck.AsCheckerProbe(probe.NewSuccessProbe),
// register the FailureProbe probe for liveness checks only
fxhealthcheck.AsCheckerProbe(probe.NewFailureProbe, healthcheck.Liveness),
// ...
)
}
```
Expand Down
6 changes: 4 additions & 2 deletions docs/modules/fxmetrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ When you use a Yokai [application template](https://ankorstore.github.io/yokai/a

## Usage

This module will enable Yokai to collect registered metrics [collectors](https://github.com/prometheus/client_golang/blob/main/prometheus/collector.go), and make available to a metrics [registry](https://github.com/prometheus/client_golang/blob/main/prometheus/registry.go) in
This module will enable Yokai to collect registered metrics [collectors](https://github.com/prometheus/client_golang/blob/main/prometheus/collector.go), and make them available to a metrics [registry](https://github.com/prometheus/client_golang/blob/main/prometheus/registry.go) in
its dependency injection system.

### Metrics creation
Expand Down Expand Up @@ -70,14 +70,15 @@ package internal

import (
"github.com/ankorstore/yokai/fxmetrics"
"github.com/foo/bar/service"
"github.com/foo/bar/internal/service"
"go.uber.org/fx"
)

func ProvideServices() fx.Option {
return fx.Options(
// register the ExampleCounter metrics collector
fxmetrics.AsMetricsCollector(service.ExampleCounter),
// ...
)
}
```
Expand All @@ -94,6 +95,7 @@ The [fxcore](https://github.com/ankorstore/yokai/tree/main/fxcore) HTTP server w
Following previous example, after invoking the `ExampleService`, the metrics endpoint will return:

```yaml title="[GET] /metrics"
# ...
# HELP example_total Example counter
# TYPE example_total counter
example_total 1
Expand Down
Loading

0 comments on commit 6f6da6d

Please sign in to comment.