Unified Server Framework
Complete server lifecycle management with transport coordination and health monitoring
Production-ready microservice development foundation
A comprehensive microservice framework for Go that provides a unified, production-ready foundation for building scalable microservices.
📖 Complete Documentation | 中文文档
pkg/server/ - Base server framework and lifecycle managementpkg/transport/ - HTTP/gRPC transport coordination layerpkg/middleware/ - Configurable middleware stackpkg/discovery/ - Service discovery integrationexamples/ - Simple examples for getting startedinternal/switserve/ - User management reference serviceinternal/switauth/ - Authentication service with JWTinternal/switctl/ - CLI tool implementationgit clone https://github.com/innovationmech/swit.git
cd swit
go mod downloadpackage main
import (
"context"
"net/http"
"github.com/gin-gonic/gin"
"github.com/innovationmech/swit/pkg/server"
)
type MyService struct{}
func (s *MyService) RegisterServices(registry server.BusinessServiceRegistry) error {
return registry.RegisterBusinessHTTPHandler(&MyHTTPHandler{})
}
type MyHTTPHandler struct{}
func (h *MyHTTPHandler) RegisterRoutes(router interface{}) error {
ginRouter := router.(*gin.Engine)
ginRouter.GET("/hello", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Hello from Swit!"})
})
return nil
}
func (h *MyHTTPHandler) GetServiceName() string {
return "my-service"
}
func main() {
config := &server.ServerConfig{
ServiceName: "my-service",
HTTP: server.HTTPConfig{Port: "8080", Enabled: true},
GRPC: server.GRPCConfig{Enabled: false},
}
service := &MyService{}
baseServer, _ := server.NewBusinessServerCore(config, service, nil)
ctx := context.Background()
baseServer.Start(ctx)
defer baseServer.Shutdown()
select {} // Keep running
}go run main.go
curl http://localhost:8080/hello# HTTP service
cd examples/simple-http-service && go run main.go
# gRPC service
cd examples/grpc-service && go run main.go
# Full-featured service
cd examples/full-featured-service && go run main.go# Build all services
make build
# Run services
./bin/swit-serve # User management (HTTP: 9000, gRPC: 10000)
./bin/swit-auth # Authentication (HTTP: 9001, gRPC: 50051)
./bin/switctl --help # CLI tool# Complete setup
make setup-dev
# Quick setup
make setup-quick# Build
make build # Full build
make build-dev # Quick build
# Test
make test # All tests
make test-dev # Quick tests
make test-coverage # Coverage report
# API Development
make proto # Generate protobuf code
make swagger # Generate API docs
# Code Quality
make tidy # Tidy modules
make format # Format code
make quality # Quality checks# Build images
make docker
# Run with Docker Compose
docker-compose up -d
# Or run individually
docker run -p 9000:9000 -p 10000:10000 swit-serve:latest
docker run -p 9001:9001 swit-auth:latestMIT License - See LICENSE file for details
For complete documentation, examples, and advanced usage, visit innovationmech.github.io/swit