Migrated project to use golang.

This commit is contained in:
2026-04-14 08:08:54 +02:00
parent 44fb025c81
commit dbf7858afd
18 changed files with 762 additions and 906 deletions
-73
View File
@@ -1,73 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Controllers;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
abstract class BaseController
{
private Psr17Factory $factory;
public function __construct()
{
$this->factory = new Psr17Factory();
}
/**
* Render a template — the template itself is responsible for including any layout.
*/
protected function render(string $template, array $data = [], int $status = 200): ResponseInterface
{
ob_start();
extract($data);
require __DIR__ . '/../views/' . $template . '.php';
$html = ob_get_clean();
return $this->response($html, $status);
}
/**
* Automatically return a partial for HTMX requests, full page otherwise.
* Each template is responsible for including its own layout if needed.
*/
protected function view(
ServerRequestInterface $request,
string $fullTemplate,
string $partialTemplate,
array $data = []
): ResponseInterface {
$template = $this->isHtmx($request) ? $partialTemplate : $fullTemplate;
return $this->render($template, $data);
}
/**
* Return a JSON response.
*/
protected function json(array $data, int $status = 200): ResponseInterface
{
return $this->response(json_encode($data), $status, 'application/json');
}
/**
* Check if the request came from HTMX.
*/
protected function isHtmx(ServerRequestInterface $request): bool
{
return $request->hasHeader('HX-Request');
}
/**
* Build a basic HTML response.
*/
private function response(string $body, int $status = 200, string $contentType = 'text/html'): ResponseInterface
{
$response = $this->factory->createResponse($status);
$response->getBody()->write($body);
return $response->withHeader('Content-Type', $contentType);
}
}
-16
View File
@@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Controllers;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class HomeController extends BaseController
{
public function index(ServerRequestInterface $request): ResponseInterface
{
return $this->render('pages/home');
}
}
-2
View File
@@ -1,2 +0,0 @@
<p> Jason testing, Here! </p>