{"id":37102441,"url":"https://github.com/softwareplace/goserve","last_synced_at":"2026-01-14T12:24:56.566Z","repository":{"id":272524299,"uuid":"916886232","full_name":"softwareplace/goserve","owner":"softwareplace","description":"goserve is a Go library designed to simplify the creation of backend applications or services that interact with HTTP requests. It leverages the powerful gorilla/mux router to provide flexibility, performance, and scalability while adhering to best practices in server development.","archived":false,"fork":false,"pushed_at":"2025-12-12T16:35:15.000Z","size":731,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-14T07:42:15.567Z","etag":null,"topics":["backend","development","go","go-library","golang","jwt","oapi-codegen","rest","rest-api","restful","server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softwareplace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-01-15T00:04:41.000Z","updated_at":"2025-12-12T16:35:20.000Z","dependencies_parsed_at":"2025-01-15T01:23:09.806Z","dependency_job_id":"c334a4a8-3f76-42b3-ad57-92a4c35d693f","html_url":"https://github.com/softwareplace/goserve","commit_stats":null,"previous_names":["softwareplace/http-utils","softwareplace/goserve"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/softwareplace/goserve","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareplace%2Fgoserve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareplace%2Fgoserve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareplace%2Fgoserve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareplace%2Fgoserve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softwareplace","download_url":"https://codeload.github.com/softwareplace/goserve/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softwareplace%2Fgoserve/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["backend","development","go","go-library","golang","jwt","oapi-codegen","rest","rest-api","restful","server"],"created_at":"2026-01-14T12:24:55.748Z","updated_at":"2026-01-14T12:24:56.398Z","avatar_url":"https://github.com/softwareplace.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goserve\n\n`goserve` is a Go library designed to simplify the creation of backend applications or services that interact with HTTP\nrequests. It leverages the powerful `gorilla/mux` router to provide flexibility, performance, and scalability while\nadhering to best practices in server development.\n\n---\n\n## 🛠️ Prerequisites\n\nBefore using goserve, make sure you have the following installed:\n\n1. **Go Programming Language**\n   👉 [Install Go](https://go.dev/doc/install)\n   ✅ Verify installation:\n   ```bash\n   go version\n   ```\n\n2. **Git** (Version Control System)\n   👉 [Install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)\n   ✅ Verify installation:\n   ```bash\n   git --version\n   ```\n\n3. **Environment Setup**\n   Add Go binaries to your `PATH`:\n   ```bash\n   export PATH=\"$HOME/go/bin:$PATH\"\n   ```\n   Add this line to your shell configuration file (e.g., `.bashrc`, `.zshrc`) to persist it.\n\n4. **oapi-codegen Tool** (for OpenAPI/Swagger integration):\n   ```bash\n   go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.2.0\n   ```\n\n---\n\n## 📦 Installation\n\nInstall the `goserve-generator` CLI tool:\n\n```bash\ngo install github.com/softwareplace/goserve/cmd/goserve-generator@latest\n```\n\nOr add the library to your Go project:\n\n```bash\ngo get -u github.com/softwareplace/goserve\n```\n\n---\n\n## 🚀 Usage\n\nGenerate a new goserve project:\n\n```bash\ngoserve-generator -n \u003cproject-name\u003e -u \u003cgithub-username\u003e [-r true|false] [-gi true|false]\n```\n\n### Flags\n\n| Flag      | Description                           | Required | Default |\n| --------- | ------------------------------------- | -------- | ------- |\n| `-n`      | Name of your project                  | ✅ Yes    |         |\n| `-u`      | Your GitHub username                  | ✅ Yes    |         |\n| `-r`      | Force replace existing files          | ❌ No     | false   |\n| `-gi`     | Gi project initialization             | ❌ No     | true    |\n| `-cgf`    | Template of the codegen config file   | ❌ No     |         |\n| `-gsv`    | Use a specific version of goserver    | ❌ No     |         |\n| `version` | Check current version                 | ❌ No     |         |\n| `update`  | Update to the latest released version | ❌ No     |         |\n\n### Example\n\n```bash\ngoserve-generator -n goserve-example -u myuser -r true -gi false\n```\n\n---\n\n## ✨ Key Features\n\n- **Backend Application Server**: Kickstart a backend server with security, role-based access control, and scalable\n  routing.\n- **Enhanced Security**: Built-in support for API key authentication using `private.key` and `public.key`.\n- **Swagger-UI Integration**: Built-in OpenAPI docs via `oapi-codegen`.\n- **Router Flexibility**: Powered by `gorilla/mux` for clean, RESTful routing.\n- **Built-in Middleware**: Support for authentication, role-checking, and structured error handling.\n\n---\n\n## 🛡️ Environment Variables\n\n| Variable Name                   | Required? | Default      | Description                          |\n| ------------------------------- | --------- | ------------ | ------------------------------------ |\n| `CONTEXT_PATH`                  | No        | `/`          | Base path for all endpoints          |\n| `PORT`                          | No        | `8080`       | Port the server listens on           |\n| `API_SECRET_KEY`                | Yes*      |              | Used in encryption/authentication    |\n| `API_PRIVATE_KEY`               | Yes*      |              | The private.key file path            |\n| `B_CRYPT_COST`                  | No        | `10`         | Cost factor for bcrypt               |\n| `LOG_DIR`                       | No        | `./.log`     | Where log files are stored           |\n| `LOG_APP_NAME`                  | No        |              | Used in the log file naming          |\n| `LOG_REPORT_CALLER`             | No        | `false`      | Enable method name reporting in logs |\n| `LOG_FILE_NAME_DATE_FORMAT`     | No        | `2006-01-02` | Date format for log filenames        |\n| `JWT_ISSUER`                    | No        |              | JWT issuer name                      |\n| `JWT_CLAIMS_ENCRYPTION_ENABLED` | No        | `true`       | Encrypt claims inside JWT            |\n| `SWAGGER_RESURCE_ENABLED`       | No        | `true`       | Enable swagger resource              |\n\n\\* Required only if using `security.Service`\n\n---\n\n## 🧪 Example: Secure Server Setup\n\n```go\npackage main\n\nimport (\n\tlog \"github.com/sirupsen/logrus\"\n\t\"github.com/softwareplace/goserve/internal/handler\"\n\t\"github.com/softwareplace/goserve/internal/service/apiservice\"\n\t\"github.com/softwareplace/goserve/internal/service/login\"\n\t\"github.com/softwareplace/goserve/internal/service/provider\"\n\t\"github.com/softwareplace/goserve/logger\"\n\t\"github.com/softwareplace/goserve/security\"\n\t\"github.com/softwareplace/goserve/security/secret\"\n\t\"github.com/softwareplace/goserve/server\"\n)\n\nfunc init() {\n\tlogger.LogSetup()\n}\n\nvar (\n\tuserPrincipalService = login.NewPrincipalService()\n\tsecurityService      = security.New(\n\t\tuserPrincipalService,\n\t)\n\tloginService   = login.NewLoginService(securityService)\n\tsecretProvider = provider.NewSecretProvider()\n\tsecretService  = secret.New(\n\t\tsecretProvider,\n\t\tsecurityService,\n\t)\n)\n\nfunc main() {\n\tserver.Default().\n\t\tLoginResourceEnabled(true).\n\t\tSecretKeyGeneratorResourceEnabled(true).\n\t\tLoginService(loginService).\n\t\tSecretService(secretService).\n\t\tSecurityService(securityService).\n\t\tEmbeddedServer(apiservice.Register).\n\t\tGet(apiservice.ReportCallerHandler, \"/report/caller\").\n\t\tSwaggerDocHandler(\"./internal/resource/pet-store.yaml\").\n\t\tStartServer()\n}\n```\n\n---\n\n## 🔧 Code Generation Config (oapi-codegen)\n\nTo customize code generation:\n\n```yaml\npackage: gen\n\ngenerate:\n  gorilla-server: true\n  models: true\n\noutput: ./gen/api.gen.go\n\noutput-options:\n  user-templates:\n    imports.tmpl: https://raw.githubusercontent.com/softwareplace/goserve/refs/heads/main/resource/templates/imports.tmpl\n    param-types.tmpl: https://raw.githubusercontent.com/softwareplace/goserve/refs/heads/main/resource/templates/param-types.tmpl\n    request-bodies.tmpl: https://raw.githubusercontent.com/softwareplace/goserve/refs/heads/main/resource/templates/request-bodies.tmpl\n    typedef.tmpl: https://raw.githubusercontent.com/softwareplace/goserve/refs/heads/main/resource/templates/typedef.tmpl\n    gorilla/gorilla-register.tmpl: https://raw.githubusercontent.com/softwareplace/goserve/refs/heads/main/resource/templates/gorilla/gorilla-register.tmpl\n    gorilla/gorilla-middleware.tmpl: https://raw.githubusercontent.com/softwareplace/goserve/refs/heads/main/resource/templates/gorilla/gorilla-middleware.tmpl\n    gorilla/gorilla-interface.tmpl: https://raw.githubusercontent.com/softwareplace/goserve/refs/heads/main/resource/templates/gorilla/gorilla-interface.tmpl\n```\n\n### Generate Code\n\n```bash\noapi-codegen --config path/to/config.yaml path/to/swagger.yaml\n```\n\n---\n\n## 📋 API Testing\n\n### Start server\n\n```bash\ngo run test/main.go\n```\n\nOpen [http://localhost:8080/swagger/index.html](http://localhost:8080/swagger/index.html)\n\n---\n\n### Start in protected mode\n\n```bash\nPROTECTED_API=true go run test/main.go\n```\n\nWithout token:\n\n```json\n{\n  \"message\": \"You are not allowed to access this resource\",\n  \"statusCode\": 401,\n  \"timestamp\": 1742781093916\n}\n```\n\nWith valid token:\n\n```bash\ncurl -X GET 'http://localhost:8080/swagger/index.html' \\\n  -H 'accept: application/json' \\\n  -H 'X-Api-Key: \u003cyour-jwt-token\u003e'\n```\n\n---\n\n## 📚 Why Choose goserve?\n\nWhether you're building microservices or full-stack applications, goserve provides a clean, secure, and production-ready\nserver foundation. With powerful integrations and easy configuration, goserve helps you focus on building features—not\nboilerplate.\n\n---\n\n## 🧩 License\n\n## 🎉 Welcome to the Open Source Community!\n\nOpen source is more than just code — it's a collaborative effort powered by you! Contributing to goserve means you're\njoining a community of developers who believe in making software more accessible, secure, and scalable for everyone.\n\nThank you for being a part of this journey! Together, we create, innovate, and grow. 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftwareplace%2Fgoserve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftwareplace%2Fgoserve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftwareplace%2Fgoserve/lists"}