{"id":29687212,"url":"https://github.com/shiftyx1/facade","last_synced_at":"2025-07-23T04:36:14.715Z","repository":{"id":305411971,"uuid":"1022778356","full_name":"ShiftyX1/Facade","owner":"ShiftyX1","description":"Easy-to-configure mock API server written in Golang","archived":false,"fork":false,"pushed_at":"2025-07-19T23:29:03.000Z","size":46,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-20T00:53:31.913Z","etag":null,"topics":["go","golang","http","mock","server","simple"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ShiftyX1.png","metadata":{"files":{"readme":"README-ru.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-19T20:02:21.000Z","updated_at":"2025-07-19T23:25:42.000Z","dependencies_parsed_at":"2025-07-20T01:05:50.018Z","dependency_job_id":null,"html_url":"https://github.com/ShiftyX1/Facade","commit_stats":null,"previous_names":["shiftyx1/facade"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ShiftyX1/Facade","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiftyX1%2FFacade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiftyX1%2FFacade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiftyX1%2FFacade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiftyX1%2FFacade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShiftyX1","download_url":"https://codeload.github.com/ShiftyX1/Facade/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShiftyX1%2FFacade/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266618988,"owners_count":23957273,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","http","mock","server","simple"],"created_at":"2025-07-23T04:36:13.693Z","updated_at":"2025-07-23T04:36:14.697Z","avatar_url":"https://github.com/ShiftyX1.png","language":"Go","readme":"# Shifty's Facade\n\n[![Go Version](https://img.shields.io/github/go-mod/go-version/ShiftyX1/Facade)](https://golang.org/)\n[![Release](https://img.shields.io/github/v/release/ShiftyX1/Facade)](https://github.com/ShiftyX1/Facade/releases)\n[![License](https://img.shields.io/github/license/ShiftyX1/Facade?label=license)](https://github.com/ShiftyX1/Facade/blob/master/LICENSE)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/ShiftyX1/Facade/ci.yml?branch=master)](https://github.com/ShiftyX1/Facade/actions)\n[![GitHub Issues](https://img.shields.io/github/issues/ShiftyX1/Facade)](https://github.com/ShiftyX1/Facade/issues)\n[![GitHub Stars](https://img.shields.io/github/stars/ShiftyX1/Facade)](https://github.com/ShiftyX1/Facade/stargazers)\n[![Last Commit](https://img.shields.io/github/last-commit/ShiftyX1/Facade)](https://github.com/ShiftyX1/Facade/commits/master)\n\nПростой и гибкий mock HTTP сервер для разработчиков.\n\n## Установка\n\n```bash\nmake build\n```\n\n## Быстрый старт\n\n1. Создайте конфигурационный файл `config.yaml`:\n\n```yaml\nserver:\n  port: 8080\n  host: localhost\n\nroutes:\n  - path: /users\n    method: GET\n    response:\n      status: 200\n      schema:\n        type: array\n        items:\n          type: object\n          properties:\n            id: {type: integer, min: 1, max: 1000}\n            name: {type: string, faker: name}\n            email: {type: string, faker: email}\n        count: 5\n\nglobal:\n  cors: true\n  log_requests: true\n```\n\n2. Запустите сервер:\n\n```bash\nmake run\n```\n\nИли собрав и запустив вручную:\n```bash\nmake build\n./build/facade -c configs/example.yaml\n```\n\n3. Тестируйте API:\n\n```bash\ncurl http://localhost:8080/users\n```\n\n## Параметры командной строки\n\n- `-c, --config` - путь к конфигурационному файлу (по умолчанию: configs/example.yaml)\n- `-p, --port` - порт сервера (переопределяет конфиг)\n- `--host` - хост сервера (переопределяет конфиг)\n- `-v, --verbose` - подробное логирование\n\n## Конфигурация\n\n### Базовая структура\n\n```yaml\nserver:\n  port: 8080\n  host: localhost\n\nroutes:\n  - path: /api/endpoint\n    method: GET\n    response:\n      status: 200\n      body: '{\"message\": \"Hello World\"}'\n\nglobal:\n  cors: true\n  delay: 100ms\n  log_requests: true\n```\n\n### Типы ответов\n\n#### Статичный ответ\n\n```yaml\n- path: /static\n  method: GET\n  response:\n    status: 200\n    body: '{\"message\": \"Static response\"}'\n```\n\n#### Шаблонизированный ответ\n\n```yaml\n- path: /users/{id}\n  method: GET\n  response:\n    status: 200\n    body: '{\"id\": {{.PathParams.id}}, \"name\": \"User {{.PathParams.id}}\"}'\n```\n\n#### Генерация по схеме\n\n```yaml\n- path: /users\n  method: GET\n  response:\n    status: 200\n    schema:\n      type: array\n      items:\n        type: object\n        properties:\n          id: {type: integer, min: 1, max: 1000}\n          name: {type: string, faker: name}\n          email: {type: string, faker: email}\n      count: 5\n```\n\n### Условные ответы\n\n```yaml\n- path: /data\n  method: GET\n  response:\n    status: 200\n    conditions:\n      - if: '{{.QueryParams.format}} == \"xml\"'\n        body: '\u003cdata\u003eXML response\u003c/data\u003e'\n      - if: '{{.QueryParams.format}} == \"json\"'\n        body: '{\"data\": \"JSON response\"}'\n      - default: true\n        body: '{\"data\": \"Default response\"}'\n```\n\n### Шаблонные функции\n\n#### Доступ к данным запроса\n\n- `{{.PathParams.id}}` - path параметры\n- `{{.QueryParams.limit}}` - query параметры  \n- `{{.Body.name}}` - данные из body запроса\n\n#### Faker данные\n\n- `{{fakerName}}` - случайное имя\n- `{{fakerEmail}}` - случайный email\n- `{{fakerPhone}}` - случайный телефон\n- `{{fakerCompany}}` - случайная компания\n- `{{fakerUUID}}` - UUID\n\n#### Случайные данные\n\n- `{{randomInt 1 100}}` - случайное число\n- `{{randomString 10}}` - случайная строка\n- `{{randomBool}}` - случайный boolean\n\n#### Дата и время\n\n- `{{now}}` - текущее время\n- `{{now.Format \"2006-01-02\"}}` - форматированная дата\n\n### Типы схем\n\n#### Примитивные типы\n\n```yaml\nproperties:\n  name: {type: string, faker: name}\n  age: {type: integer, min: 18, max: 65}\n  price: {type: number, min: 0.1, max: 999.99}\n  active: {type: boolean}\n```\n\n#### Массивы\n\n```yaml\nschema:\n  type: array\n  items:\n    type: object\n    properties:\n      id: {type: integer}\n      name: {type: string}\n  count: 10\n```\n\n#### Объекты\n\n```yaml\nschema:\n  type: object\n  properties:\n    user:\n      type: object\n      properties:\n        id: {type: integer}\n        profile:\n          type: object\n          properties:\n            name: {type: string, faker: name}\n```\n\n### Faker типы\n\n- `name` - имя человека\n- `email` - email адрес\n- `phone` - номер телефона\n- `address` - адрес\n- `company` - название компании\n- `word` - случайное слово\n- `sentence` - предложение\n- `paragraph` - параграф\n- `url` - URL\n- `uuid` - UUID\n- `date` - дата\n- `timestamp` - timestamp\n\n### Системные endpoints\n\nFacade предоставляет системные endpoints для управления:\n\n- `GET /_facade/health` - проверка состояния сервера\n- `GET /_facade/state` - получение всего состояния\n- `DELETE /_facade/state` - очистка состояния\n- `GET /_facade/state/keys` - получение ключей состояния\n\n### Stateful режим\n\nFacade автоматически сохраняет данные из POST/PUT запросов и может использовать их в последующих GET запросах.\n\nПример сохранения пользователя:\n\n```bash\n# Создание пользователя\ncurl -X POST http://localhost:8080/users \\\n  -d '{\"name\": \"John Doe\", \"email\": \"john@example.com\"}'\n\n# Получение состояния\ncurl http://localhost:8080/_facade/state\n```\n\n## Команды сборки и запуска\n\n### Основные команды Makefile\n\n```bash\nmake help          # Показать все доступные команды\nmake build         # Собрать приложение в build/facade\nmake run           # Собрать и запустить с примером конфигурации\nmake clean         # Очистить файлы сборки\nmake deps          # Установить/обновить зависимости\nmake build-all     # Кросс-компиляция для всех платформ\n```\n\n### Запуск с различными конфигурациями\n\n```bash\n# Запуск с примером конфигурации\nmake run\n\n# Запуск с кастомной конфигурацией\n./build/facade -c configs/frontend-dev.yaml -v\n\n# Запуск с переопределением порта\n./build/facade -c configs/testing.yaml -p 9000 -v\n```\n\n## Тестирование\n\n### Базовое тестирование\n\nПосле запуска сервера (`make run`) можно протестировать API:\n\n```bash\n# Проверка здоровья сервера\ncurl http://localhost:8080/_facade/health\n\n# Получение списка пользователей (генерация по схеме)\ncurl http://localhost:8080/users | jq\n\n# Получение конкретного пользователя (шаблонизация)\ncurl http://localhost:8080/users/123 | jq\n\n# Создание пользователя (POST с данными)\ncurl -X POST http://localhost:8080/users \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"name\": \"John Doe\", \"email\": \"john@example.com\"}' | jq\n\n# Проверка состояния после POST\ncurl http://localhost:8080/_facade/state | jq\n\n# Тестирование условной логики\ncurl \"http://localhost:8080/products?category=electronics\" | jq\ncurl \"http://localhost:8080/products\" | jq\n\n# Тестирование query параметров\ncurl \"http://localhost:8080/search?q=test\u0026limit=10\" | jq\n```\n\n### Тестирование конфигурации testing.yaml\n\n```bash\n# Запуск тестового сервера\n./build/facade -c configs/testing.yaml -v\n\n# Успешный платеж\ncurl -X POST http://localhost:8081/api/payments \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"amount\": \"500\", \"card_number\": \"4111111111111111\"}' | jq\n\n# Платеж с верификацией (сумма \u003e 1000)\ncurl -X POST http://localhost:8081/api/payments \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"amount\": \"1500\", \"card_number\": \"4111111111111111\"}' | jq\n\n# Отклоненный платеж\ncurl -X POST http://localhost:8081/api/payments \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"amount\": \"100\", \"card_number\": \"4000000000000002\"}' | jq\n\n# Статусы заказов\ncurl http://localhost:8081/api/orders/1/status | jq  # pending\ncurl http://localhost:8081/api/orders/2/status | jq  # shipped\ncurl http://localhost:8081/api/orders/3/status | jq  # delivered\ncurl http://localhost:8081/api/orders/999/status | jq # not found\n\n# Симуляция ошибок\ncurl http://localhost:8081/api/error/500 | jq\ncurl http://localhost:8081/api/error/404 | jq\ncurl http://localhost:8081/api/error/401 | jq\n\n# Медленный endpoint (5 секунд задержки)\ntime curl http://localhost:8081/api/slow | jq\n```\n\n## Примеры использования\n\n### Frontend разработка\n\nНастройте Facade как backend для разработки frontend приложения:\n\n```yaml\nserver:\n  port: 3001\n\nroutes:\n  - path: /api/auth/login\n    method: POST\n    response:\n      status: 200\n      body: '{\"token\": \"{{fakerUUID}}\", \"user\": {\"id\": 1, \"name\": \"{{.Body.username}}\"}}'\n\n  - path: /api/users\n    method: GET\n    response:\n      status: 200\n      schema:\n        type: array\n        items:\n          type: object\n          properties:\n            id: {type: integer, min: 1, max: 1000}\n            name: {type: string, faker: name}\n            avatar: {type: string, faker: url}\n        count: 20\n\nglobal:\n  cors: true\n  delay: 200ms\n```\n\n### Тестирование интеграций\n\nСимуляция различных сценариев для тестов:\n\n```yaml\nroutes:\n  - path: /api/payment\n    method: POST\n    response:\n      status: 200\n      conditions:\n        - if: '{{.Body.amount}} \u003e \"1000\"'\n          body: '{\"status\": \"pending\", \"id\": \"{{fakerUUID}}\"}'\n        - if: '{{.Body.card_number}} == \"4111111111111111\"'\n          body: '{\"status\": \"success\", \"id\": \"{{fakerUUID}}\"}'\n        - default: true\n          status: 400\n          body: '{\"error\": \"Invalid card\"}'\n```\n\n### Демонстрация API\n\nСоздание реалистичного API для демонстраций:\n\n```yaml\nroutes:\n  - path: /api/products\n    method: GET\n    response:\n      status: 200\n      schema:\n        type: object\n        properties:\n          data:\n            type: array\n            items:\n              type: object\n              properties:\n                id: {type: integer, min: 1, max: 1000}\n                name: {type: string, faker: word}\n                description: {type: string, faker: sentence}\n                price: {type: number, min: 10, max: 500}\n                image: {type: string, faker: url}\n                category: {type: string, faker: word}\n            count: 12\n          total: {type: integer, min: 100, max: 1000}\n          page: 1\n          per_page: 12\n```\n\n## Сборка и развертывание\n\n### Использование Makefile (рекомендуется)\n\n```bash\n# Показать все доступные команды\nmake help\n\n# Быстрый старт - собрать и запустить\nmake run\n\n# Только сборка\nmake build\n\n# Очистка\nmake clean\n\n# Кросс-компиляция для всех платформ\nmake build-all\n```\n\n### Ручная сборка\n\n```bash\n# Локальная сборка\nmkdir -p build\ngo build -o build/facade cmd/facade/main.go\n\n# Запуск\n./build/facade -c configs/example.yaml\n```\n\n## Лицензия\n\nMIT License - см. файл LICENSE для деталей.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiftyx1%2Ffacade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshiftyx1%2Ffacade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiftyx1%2Ffacade/lists"}