Skip to content

A Go toolkit that reduces microservice boilerplate by standardizing how services interact with infrastructure such as messaging systems, network calls, and shared service utilities.

License

Notifications You must be signed in to change notification settings

fesTech-cloud/microkit

Repository files navigation

microkit

Go Reference Go Report Card License: MIT

An opinionated Go toolkit that simplifies building microservices by providing clean abstractions over common infrastructure tools like messaging, networking, and service communication.


Why microkit?

Building microservices in Go often means rewriting the same infrastructure code:

  • Messaging setup
  • Network calls
  • Retries and timeouts
  • Graceful shutdown
  • Error handling

microkit standardizes these patterns with clear, minimal abstractions so developers can focus on business logic instead of boilerplate.

This is not a framework. It’s a toolkit you can adopt incrementally.


Getting Started

Installation

go get github.com/festus/microkit

Quick Start

HTTP Client with Retry

package main

import (
    "context"
    "fmt"
    "time"
    
    microhttp "github.com/festus/microkit/adapters/http"
    "github.com/festus/microkit/network"
)

func main() {
    client := microhttp.NewClient(10 * time.Second)
    defer client.Close()
    
    resp, err := client.Get(context.Background(), "https://api.example.com",
        network.WithHeader("Authorization", "Bearer token"),
        network.WithRetry(3, 100*time.Millisecond, 2*time.Second, 2.0),
    )
    if err != nil {
        panic(err)
    }
    
    fmt.Printf("Response: %d\n", resp.StatusCode)
}

Kafka Consumer with Retry/DLQ

package main

import (
    "context"
    "fmt"
    "time"
    
    "github.com/festus/microkit/adapters/kafka"
    "github.com/festus/microkit/internal/retry"
)

func main() {
    conn := kafka.NewConnection([]string{"localhost:9092"})
    
    config := kafka.ConsumerConfig{
        RetryConfig: retry.Config{
            MaxAttempts:  3,
            InitialDelay: 100 * time.Millisecond,
            MaxDelay:     2 * time.Second,
            Multiplier:   2.0,
        },
        EnableDLQ: true,
        DLQTopic:  "orders-dlq",
    }
    
    consumer := kafka.NewConsumerWithConfig(conn, "orders", "order-service", config)
    defer consumer.Close()
    
    consumer.Subscribe(context.Background(), func(msg []byte) error {
        fmt.Printf("Processing: %s\n", string(msg))
        // Your business logic here
        return nil
    })
    
    select {} // Keep running
}

Current Focus

  • Messaging abstractions
  • Network abstractions (HTTP & gRPC)
  • RabbitMQ adapter (v0.1)
  • Kafka adapter (v0.1)
  • HTTP adapter (v0.1)
  • gRPC adapter (v0.1)

Examples

RabbitMQ

producer, _ := rabbitmq.NewProducer(
    rabbitmq.WithURL("amqp://localhost"),
)

producer.Publish(ctx, "orders.created", messaging.Message{
    Payload: []byte(`{"id":"123"}`),
})

Kafka

conn := kafka.NewConnection([]string{"localhost:9092"})
producer := kafka.NewProducer(conn, "orders")

producer.Publish(ctx, []byte("key"), []byte(`{"id":"123"}`))

HTTP Client with Retry

client := microhttp.NewClient(10 * time.Second)
defer client.Close()

resp, _ := client.Get(ctx, "https://api.example.com/users",
    network.WithHeader("Authorization", "Bearer token"),
    network.WithRetry(3, 100*time.Millisecond, 2*time.Second, 2.0),
)

HTTP Client with Status Code Retry

// Retry on 429 (rate limit) and 503 (service unavailable)
resp, _ := client.Get(ctx, "https://api.example.com/users",
    network.WithRetryOnStatus(3, 100*time.Millisecond, 2*time.Second, 2.0, 429, 503),
)

gRPC Client with Retry

client, _ := grpc.NewClient("localhost:50051", 10*time.Second)
defer client.Close()

req := &HelloRequest{Name: "microkit"}
resp := &HelloResponse{}

client.Call(ctx, "/hello.HelloService/SayHello", req, resp,
    network.WithRetry(3, 100*time.Millisecond, 2*time.Second, 2.0),
)

About

A Go toolkit that reduces microservice boilerplate by standardizing how services interact with infrastructure such as messaging systems, network calls, and shared service utilities.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages