yarbay

package module
v0.0.0-...-6608339 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

README

yarbay

Microservice Application SDK

W.I.P

This project is heavily in development, please Do NOT use in production.

Components

  • Database [SQLite, PostgreSQL]
  • HTTP Router [Fiber]
  • Vector Database [Elasticsearch]
  • Tracing [OpenTelemetry]
  • Message Broker [NATS]
  • GRPC Server
  • In-Memory Store

Installation

  go get github.com/guneyin/yarbay

Usage/Examples

package main

import (
	"fmt"
	"github.com/guneyin/yarbay"
	"github.com/guneyin/yarbay/modules/db"
	"github.com/guneyin/yarbay/modules/elastic"
	"github.com/guneyin/yarbay/modules/fiber"
	"github.com/guneyin/yarbay/modules/grpc"
	"github.com/guneyin/yarbay/modules/nats"
	"github.com/guneyin/yarbay/modules/otel"
	"github.com/guneyin/yarbay/modules/store"
	"log"
	"time"
)

const (
	appName  = "yarbay-demo-app"
	appTitle = "Yarbay Demo App"
)

func main() {
	app := yarbay.NewApp(&yarbay.Config{
		Name:  appName,
		Title: appTitle,
	}).
		WithFiber(fiber.New(&fiber.Config{
			AppName: appName,
			Port:    "8000",
			Timeout: time.Second * 30,
		}).WithSwagger(&fiber.SwaggerConfig{
			HostURL:  "127.0.0.1:8000",
			BasePath: "/",
			FilePath: "./docs/swagger.json",
			Path:     "/docs",
			Title:    fmt.Sprintf("%s - API Documentation", appTitle),
		})).
		WithDB(db.NewMemoryDB().WithMigrate(tables...)).
		WithStore(store.New()).
		WithGRPC(grpc.New(&grpc.Config{
			Port:    "8001",
			Timeout: time.Second * 10,
		})).
		WithOtel(otel.New(&otel.Config{
			AppName:   appName,
			ExportURL: "127.0.0.1:5468",
		})).
		WithElastic(elastic.New("http://127.0.0.1:9200")).
		WithNATS(nats.New("nats://127.0.0.1:4222"))

	service := NewService()
	app.RegisterService(service)

	log.Fatal(app.Start())
}

Test Application

TestApp is wrapper of App with default modules and helper functions. It's useful to build integration tests via Testcontainers

Usage
SetupTest
package main

import (
	"github.com/guneyin/yarbay"
	"github.com/guneyin/yarbay/modules/db"
	"github.com/guneyin/yarbay/modules/fiber"
	"github.com/guneyin/yarbay/modules/nats"
)

var (
	testApp     *yarbay.TestApp
	testService *Service
)

func setupTest() error {
	testApp = yarbay.NewTestApp().
		WithFiber(fiber.NewTest()).
		WithDB(db.NewMemoryDB().WithMigrate(tables...)).
		WithNATS(nats.NewTest())

	testService = NewService()
	testApp.RegisterService(testService)
	
	return nil
}
IntegrationTest
func TestIntegration(t *testing.T) {
	if testing.Short() {
		t.Skip("Skipping integration test")
	}

	tapp := NewTestApp()
	err := tapp.RunTests(t,
		test1,
		test2,
	)
	assert.NoError(t, err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func NewApp

func NewApp(config *Config) *App

func (*App) Bootstrapped

func (a *App) Bootstrapped() bool

func (*App) Market

func (a *App) Market() modules.Market

func (*App) RegisterService

func (a *App) RegisterService(s Service)

func (*App) Start

func (a *App) Start() error

func (*App) Stop

func (a *App) Stop()

func (*App) WithDB

func (a *App) WithDB(db *db.DB) *App

func (*App) WithElastic

func (a *App) WithElastic(elastic *elastic.Elastic) *App

func (*App) WithFiber

func (a *App) WithFiber(fiber *fiber.Fiber) *App

func (*App) WithGRPC

func (a *App) WithGRPC(grpc *grpc.GRPC) *App

func (*App) WithNATS

func (a *App) WithNATS(nats *nats.NATS) *App

func (*App) WithOtel

func (a *App) WithOtel(otel *otel.Otel) *App

func (*App) WithStore

func (a *App) WithStore(store *store.Store) *App

type Config

type Config struct {
	Name  string
	Title string
}

type Service

type Service interface {
	Boostrap(m modules.Market)
}

type TestApp

type TestApp struct {
	*App
}

func NewTestApp

func NewTestApp() *TestApp

func (*TestApp) RunTest

func (ta *TestApp) RunTest(t *testing.T, tests ...func(t *testing.T, a *TestApp)) error

func (*TestApp) WithDB

func (ta *TestApp) WithDB(db *db.DB) *TestApp

func (*TestApp) WithElastic

func (ta *TestApp) WithElastic(elastic *elastic.Elastic) *TestApp

func (*TestApp) WithFiber

func (ta *TestApp) WithFiber(fiber *fiber.Fiber) *TestApp

func (*TestApp) WithGRPC

func (ta *TestApp) WithGRPC(grpc *grpc.GRPC) *TestApp

func (*TestApp) WithNATS

func (ta *TestApp) WithNATS(nats *nats.NATS) *TestApp

func (*TestApp) WithOtel

func (ta *TestApp) WithOtel(otel *otel.Otel) *TestApp

func (*TestApp) WithStore

func (ta *TestApp) WithStore(store *store.Store) *TestApp

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL