Skip to content

lkendrickd/echo-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Echo-Server

Echo Server Logo

This is a simple echo server that utilizes the new features in Go 1.22. I wanted to showcase an example that now we do not need to use external libraries to handle the HTTP server and the routing.

Features:

  • HTTP Server
  • Routing
  • Middleware
  • Structured Logging
  • Prometheus Metrics
  • Flag and Environment Variable Configuration

Endpoints:

  • GET /health: Returns the health of the server
  • POST api/v1/echo: Returns the body of the request
  • GET /metrics: Returns the metrics of the server

Usage:

go run cmd/echo-service.go

Configuration:

Note that environment variables for PORT and LOG_LEVEL take precedence over the flags.

Make Native Go Execution:

make build
make run

Docker Execution:

make docker-run

Curl Examples:

Health Check:

curl http://localhost:8080/health

Echo:

curl -X POST http://localhost:8080/api/v1/echo -d '{"message":"Hello World"}'

Metrics:

curl http://localhost:8080/metrics

Cleanup - When done with Docker Execution:

make docker-clean

Expansion:

To add on or remove an endpoint just manipulate this section under server/server.go

func (s *Server) SetupRoutes() {}

Then add a handler for your route under handlers/handlers.go it's that simple.

This is to show that frameworks really are unnecessary for microservices with the new features in Go 1.22.

About

Example microservice with built in features

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published