An opinionated Go toolkit that simplifies building microservices by providing clean abstractions over common infrastructure tools like messaging, networking, and service communication.
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.
go get github.com/festus/microkitpackage 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)
}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
}- Messaging abstractions
- Network abstractions (HTTP & gRPC)
- RabbitMQ adapter (v0.1)
- Kafka adapter (v0.1)
- HTTP adapter (v0.1)
- gRPC adapter (v0.1)
producer, _ := rabbitmq.NewProducer(
rabbitmq.WithURL("amqp://localhost"),
)
producer.Publish(ctx, "orders.created", messaging.Message{
Payload: []byte(`{"id":"123"}`),
})conn := kafka.NewConnection([]string{"localhost:9092"})
producer := kafka.NewProducer(conn, "orders")
producer.Publish(ctx, []byte("key"), []byte(`{"id":"123"}`))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),
)// 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),
)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),
)