Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions app_go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Lab01 — DevOps Info Service

## Overview

**DevOps Info Service (Go version)** is a lightweight web application written in Go that provides detailed information about the service itself, the system it runs on, and its runtime environment.

This implementation is part of the **bonus task** for Lab 01 and is intended to demonstrate the advantages of using a compiled language in DevOps workflows, especially for containerization and multi-stage Docker builds.

**Features:**

* `GET /` — returns service, system, runtime, and request information
* `GET /health` — simple health check endpoint
* Configurable via environment variables

---

## Prerequisites

* Go **1.24.5**

---

## Installation

1. Clone the repository:

```bash
git clone https://github.com/Daniil20xx/DevOps-Core-Course.git
```

2. Navigate to the Go application directory:

```bash
cd app_go
```

3. Initialize Go module (if not already initialized):

```bash
go mod init devops-info-service
```

---

## Running the Application

### Run directly

```bash
cd app_go
go run main.go
```

By default, the service runs on:

```
http://0.0.0.0:5000
```

### Run with custom configuration

```bash
HOST=127.0.0.1 PORT=8080 go run main.go
```

---

## API Endpoints

### `GET /`

Returns detailed information about the service and the system.

**Example:**

```json
{
"endpoints": [
{
"description": "Service information",
"method": "GET",
"path": "/"
},
{
"description": "Health check",
"method": "GET",
"path": "/health"
}
],
"request": {
"client_ip": "::1",
"method": "GET",
"path": "/",
"user_agent": "Mozilla/5.0 (Windows NT; Windows NT 10.0; ru-RU) WindowsPowerShell/5.1.26100.7462"
},
"runtime": {
"current_time": "2026-01-28T08:32:20Z",
"timezone": "UTC",
"uptime_human": "0 hours, 24 minutes",
"uptime_seconds": 1452
},
"service": {
"description": "DevOps course info service",
"framework": "net/http",
"name": "devops-info-service",
"version": "1.0.0"
},
"system": {
"architecture": "amd64",
"cpu_count": 16,
"go_version": "go1.24.5",
"hostname": "Daniil",
"platform": "windows",
"platform_version": "go1.24.5"
}
}
```

---

### `GET /health`

Returns service health status.

**Example:**

```bash
curl http://localhost:8080/health
```

**Response:**

```json
{
"status": "healthy",
"timestamp": "2026-01-28T08:33:26Z",
"uptime_seconds": 1518
}
```

---

## Configuration

The application can be configured using environment variables:

| Environment Variable | Default | Description |
| -------------------- | --------- | ---------------------------------- |
| `HOST` | `0.0.0.0` | Host address to bind the server |
| `PORT` | `8080` | Port to run the application on |

---

## Project Structure

```
app_go/
├── main.go
├── go.mod
├── README.md
└── docs/
├── LAB01.md
└── screenshots/
```
60 changes: 60 additions & 0 deletions app_go/docs/GO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# GO — Language Selection Justification

## Overview

For the bonus part of Lab 01, the DevOps Info Service was reimplemented using **Go**, a compiled programming language widely used in modern DevOps.
The goal of this implementation is to demonstrate the advantages of compiled languages in terms of performance, deployment, and containerization.

---

## Why Go?

Go was selected for the following reasons:

### 1. Compiled Language

Go compiles source code into a **single native binary**, which eliminates the need for a runtime interpreter (unlike Python).
This results in:

* Faster application startup
* Lower runtime overhead
* Simpler deployment process

---

### 2. Standard Library for Web Services

Go provides a powerful and production-ready HTTP server through the standard `net/http` package.
This allows building web services without relying on external frameworks, reducing dependencies and potential security risks.

---

### 3. Performance and Resource Efficiency

Compared to interpreted languages, Go applications:

* Use less memory
* Handle concurrent requests efficiently
* Scale well under load

This makes Go a popular choice for infrastructure tools, monitoring systems, and backend services.

---

## Comparison with Python Implementation

| Aspect | Python (Flask) | Go |
| --------------------- | ----------------------- | ----------------------- |
| Language Type | Interpreted | Compiled |
| Startup Time | Slower | Faster |
| Deployment | Requires Python runtime | Single binary |
| Docker Image Size | Larger | Smaller |
| Performance | Good for small services | High |
| Dependency Management | External packages | Mostly standard library |

---

## Conclusion

Go was chosen for the bonus implementation because it provides a clean, efficient, and production-ready approach to building web services.
Using Go alongside Python in this lab demonstrates the trade-offs between interpreted and compiled languages and prepares the project for future DevOps tasks such as containerization, CI/CD pipelines, and Kubernetes deployments.
143 changes: 143 additions & 0 deletions app_go/docs/LAB01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# LAB01 — DevOps Info Service (Go Version)

## 1. Framework / Language Selection

**Chosen Language:** Go (Golang) 1.24.5

**Justification:**
Go is a compiled language suitable for building lightweight, high-performance web services.

---

## 2. Best Practices Applied

**1. Clean Code Structure**

* Separation of concerns: utility functions, handlers, and main server logic
* `getUptime()` function calculates runtime
* Route handlers: `mainHandler` for `/`, `healthHandler` for `/health`
* Consistent logging of requests

**2. Error Handling**

* Returns default page `/` if error happens

**3. Logging**

* Uses Go’s standard `log` package
* Optional verbose logging via `DEBUG` environment variable

**4. Environment Configuration**

* `HOST`, `PORT`, `DEBUG` are configurable through environment variables

**5. Dependency Management**

* Uses Go modules (`go.mod`) to track dependencies

---

## 3. API Documentation

### `GET /`

Returns service, system, runtime, and request information.

**Example Request:**

```bash
curl http://localhost:8080/
```

**Sample Response:**

```json
{
"endpoints": [
{
"description": "Service information",
"method": "GET",
"path": "/"
},
{
"description": "Health check",
"method": "GET",
"path": "/health"
}
],
"request": {
"client_ip": "::1",
"method": "GET",
"path": "/",
"user_agent": "Mozilla/5.0 (Windows NT; Windows NT 10.0; ru-RU) WindowsPowerShell/5.1.26100.7462"
},
"runtime": {
"current_time": "2026-01-28T08:32:20Z",
"timezone": "UTC",
"uptime_human": "0 hours, 24 minutes",
"uptime_seconds": 1452
},
"service": {
"description": "DevOps course info service",
"framework": "net/http",
"name": "devops-info-service",
"version": "1.0.0"
},
"system": {
"architecture": "amd64",
"cpu_count": 16,
"go_version": "go1.24.5",
"hostname": "Daniil",
"platform": "windows",
"platform_version": "go1.24.5"
}
}
```

---

### `GET /health`

Returns health status.

**Example Request:**

```bash
curl http://localhost:8080/health
```

**Sample Response:**

```json
{
"status": "healthy",
"timestamp": "2026-01-28T08:33:26Z",
"uptime_seconds": 1518
}
```

---

## 4. Testing Evidence

* **Main Endpoint:**
![Main endpoint](screenshots/01-main-endpoint.png)

* **Health Check:**
![Health endpoint](screenshots/02-health-check.png)

* **Command-line Test Example:**

```bash
curl http://localhost:8080/
curl http://localhost:8080/health
```

---

## 6. Summary

The Go implementation mirrors the Python (Flask) version of the DevOps Info Service:

* Same endpoints and JSON structure
* Faster startup and compiled binary
Binary file added app_go/docs/screenshots/01-main-endpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app_go/docs/screenshots/02-health-check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app_go/docs/screenshots/03-formatted-output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app_go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module app_go

go 1.24.5
Loading