{"id":43919083,"url":"https://github.com/spcent/golang_simple_server","last_synced_at":"2026-02-06T22:06:29.033Z","repository":{"id":312975452,"uuid":"1049487592","full_name":"spcent/golang_simple_server","owner":"spcent","description":"Minimal Go HTTP server with routing, middleware, and graceful shutdown","archived":false,"fork":false,"pushed_at":"2025-12-26T05:57:10.000Z","size":485,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-27T00:12:58.407Z","etag":null,"topics":["framework","golang","http-server","web-api","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spcent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-03T03:58:02.000Z","updated_at":"2025-12-26T05:57:06.000Z","dependencies_parsed_at":"2025-09-03T07:12:53.832Z","dependency_job_id":"9cd3dc56-e4ba-45d2-ad40-ccec23d25712","html_url":"https://github.com/spcent/golang_simple_server","commit_stats":null,"previous_names":["spcent/golang_simple_server"],"tags_count":8,"template":true,"template_full_name":null,"purl":"pkg:github/spcent/golang_simple_server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcent%2Fgolang_simple_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcent%2Fgolang_simple_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcent%2Fgolang_simple_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcent%2Fgolang_simple_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spcent","download_url":"https://codeload.github.com/spcent/golang_simple_server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spcent%2Fgolang_simple_server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29178598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T20:14:21.878Z","status":"ssl_error","status_checked_at":"2026-02-06T20:14:21.443Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["framework","golang","http-server","web-api","websocket"],"created_at":"2026-02-06T22:06:26.533Z","updated_at":"2026-02-06T22:06:29.026Z","avatar_url":"https://github.com/spcent.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Minimal Go HTTP server with routing, middleware, and graceful shutdown\n\n## Overview\n\nA lightweight HTTP server skeleton built with the Go standard library.\nIt includes dynamic routing, middleware, graceful shutdown, and environment-based configuration — ideal for quickly building simple APIs or learning HTTP server development.\n\n## Features\n\n* **Dynamic Routing**: Supports path parameters like `/hello/:name`\n* **Middleware System**: Built-in Logging and Auth middlewares, with support for custom extensions\n* **Graceful Shutdown**: Cleans up connections within 5 seconds after receiving an interrupt signal\n* **Logging**: Add glog logging library for structured logging\n* **Env Configuration**: Supports `.env` files (e.g., log level, etc.)\n* **Test Coverage**: Includes tests for routing, middleware, 404 handling, and more\n* **Developer Toolchain**: Comes with a `Makefile` and `dev.sh` script for easy build/run/test workflows\n* **Static Frontend Hosting**: Serve built Node/Next.js bundles directly from the Go server (flag: `-frontend-dir`, env: `FRONTEND_DIR`)\n\n## Getting Started\n\n### Requirements\n\n* Go 1.18+\n\n### Build \u0026 Run\n\n```bash\n# Using Makefile\nmake run   # Build and start the server (default port: 8080)\n\n# Or using the dev.sh script\n./dev.sh run\n```\n\n### Custom Port\n\n```bash\n./golang_simple_server -addr :9090  # Start on port 9090\n```\n\n### Serve a built Node/Next.js frontend\n\nPoint the server at a production build directory (for example `next export` output in `./web/out`):\n\n```bash\n./golang_simple_server -frontend-dir ./web/out\n# or\nFRONTEND_DIR=./web/out ./golang_simple_server\n```\n\nThe `-frontend-dir` flag has the highest priority and overrides `FRONTEND_DIR`.\n\nAll assets under the directory are served with SPA-style fallback to `index.html`, making it suitable for exported Next.js/Vite/React builds.\n\nTo ship a single self-contained binary, copy your built frontend (the same `frontend-dir` contents) into `pkg/frontend/embedded/` before building:\n\n```bash\ncp -r ./web/out/* pkg/frontend/embedded/\ngo build ./...\n./golang_simple_server  # mounts embedded assets when no frontend dir/env is provided\n```\n\n## Routing\n\nRegister parameterized routes with `app.(Get|Post|Delete|Put)` (see `main.go` for examples):\n\n```go\napp.Get(\"/hello/:name\", func(w http.ResponseWriter, r *http.Request) {\n    params := router.ParamsFromContext(r.Context())\n    // Access params[\"name\"]\n    fmt.Fprintf(w, `{\"message\":\"Hello, %s!\"}`, params[\"name\"])\n})\n\napp.Get(\"/users/:id/posts/:postID\", func(w http.ResponseWriter, r *http.Request) {\n    params := router.ParamsFromContext(r.Context())\n    // Access params[\"id\"] and params[\"postID\"]\n    fmt.Fprintf(w, `{\"message\":\"User %s, Post %s\"}`, params[\"id\"], params[\"postID\"])\n})\n```\n\n## Route Testing\nAfter starting the service, test the routes using curl:\n```bash\ncurl http://localhost:8080/ping # pong\ncurl http://localhost:8080/hello # {\"message\":\"Hello, World!\"}\ncurl -H \"X-Token: secret\" http://localhost:8080/hello/Alice # {\"message\":\"Hello, Alice!\"}\n```\n\n## Middleware\n\n* **LoggingMiddleware**: Logs request duration (`[time] METHOD PATH (duration)`)\n* **AuthMiddleware**: Validates `X-Token` header\n* **CorsMiddleware**: Allow cross-domain requests\n\nCombine middlewares (see `main.go` for usage):\n\n```go\napp.Use(app.Logging(), app.Auth())\n```\n\n## Testing\n\n```bash\nmake test       # Run all tests\nmake coverage   # Generate coverage report (outputs to coverage.html)\n```\n\n## Usage\n\n* **[English](docs/en/usage.md)**: Comprehensive guide with examples\n* **[中文](docs/cn/usage.md)**: 中文文档，包含详细的使用说明和示例\n\n## License\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspcent%2Fgolang_simple_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspcent%2Fgolang_simple_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspcent%2Fgolang_simple_server/lists"}