{"id":23034714,"url":"https://github.com/ibnaleem/cc-validation-webserver","last_synced_at":"2026-02-03T15:06:29.302Z","repository":{"id":261792392,"uuid":"885307316","full_name":"ibnaleem/cc-validation-webserver","owner":"ibnaleem","description":"A lightweight web server for validating credit card numbers, written in Go.","archived":false,"fork":false,"pushed_at":"2024-11-08T12:50:54.000Z","size":38,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T17:51:43.408Z","etag":null,"topics":["backend","cc-validation","cc-validator","credit-card","credit-card-checker","credit-card-fraud","credit-card-fraud-detection","credit-card-validation","credit-card-validator","go","golang","webserver","webservers"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ibnaleem.png","metadata":{"files":{"readme":"README.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}},"created_at":"2024-11-08T10:35:29.000Z","updated_at":"2024-11-11T10:44:05.000Z","dependencies_parsed_at":"2024-11-08T13:40:43.873Z","dependency_job_id":"4953e461-9c8a-4c87-ae21-f0b017815fa3","html_url":"https://github.com/ibnaleem/cc-validation-webserver","commit_stats":null,"previous_names":["ibnaleem/cc-validation-webserver"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ibnaleem/cc-validation-webserver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibnaleem%2Fcc-validation-webserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibnaleem%2Fcc-validation-webserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibnaleem%2Fcc-validation-webserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibnaleem%2Fcc-validation-webserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibnaleem","download_url":"https://codeload.github.com/ibnaleem/cc-validation-webserver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibnaleem%2Fcc-validation-webserver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260878327,"owners_count":23075959,"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","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","cc-validation","cc-validator","credit-card","credit-card-checker","credit-card-fraud","credit-card-fraud-detection","credit-card-validation","credit-card-validator","go","golang","webserver","webservers"],"created_at":"2024-12-15T16:35:03.680Z","updated_at":"2026-02-03T15:06:22.330Z","avatar_url":"https://github.com/ibnaleem.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![build](https://github.com/ibnaleem/cc-validation-webserver/actions/workflows/go.yml/badge.svg?event=push)\n# Credit Card Validation Webserver\nA lightweight web server for validating credit card numbers, written in Go.\n\n## Table of Contents\n\n- [Requirements](#requirements)\n- [Building the Webserver](#building-the-webserver)\n- [Running the Server](#running-the-server)\n- [Endpoints](#endpoints)\n  - [Root Endpoint (`/`)](#root-endpoint-)\n- [Customisation](#customisation)\n  - [Changing the Port](#changing-the-port)\n  - [Changing the Path](#changing-the-path)\n\n## Requirements\n\n- Go 1.22.5 or later.\n- A terminal or command prompt to run the application.\n\n## Building the Webserver\n\n1. Clone the repository to your local machine:\n   ```bash\n   $ git clone https://github.com/ibnaleem/cc-validation-webserver.git\n   $ cd cc-validation-webserver \n   ```\n\n2. Initialise Go modules if you haven't done so:\n   ```bash\n   $ go mod tidy\n   ```\n\n3. Build the webserver:\n   ```bash\n   $ go build\n   ```\n\n4. This will create the binary `./webserver`.\n\n## Running the Server\n\n```bash\n$ ./webserver\n```\n\nBy default, the server will start on port `3333`:\n\n```\n:: Webserver started on port 3333 ::\n```\n\nYou can then access the server at `http://127.0.0.1:3333/`.\n\n## Endpoints\n\n### Root Endpoint (`/`)\n\n- **Method**: `POST`\n- **Content-Type**: `application/json`\n- **Request Payload**:\n  \n  The server expects a JSON payload containing a `credit-card` field. The value of this field should be a string representing the credit card number you want to validate.\n\n  Example request:\n  ```json\n  {\n      \"credit-card\": \"378282246310005\"\n  }\n  ```\n\n- **Response**:\n  \n  The server will respond with a string value (`true` or `false`) depending on whether the credit card number is valid according to the [Luhn algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm).\n\n  - `true`: If the credit card number is valid.\n  - `false`: If the credit card number is invalid.\n\n  Example response:\n  ```json\n  true\n  ```\n\n### Error Responses:\n\n- **Invalid JSON**: If the provided JSON is malformed.\n  - Status code: `400 Bad Request`\n  - Example response:\n    ```json\n    {\"error\": \"Invalid JSON\"}\n    ```\n\n- **Missing Credit Card Field**: If the JSON does not contain the `credit-card` field.\n  - Status code: `400 Bad Request`\n  - Example response:\n    ```json\n    {\"error\": \"Missing expected field in JSON\"}\n    ```\n\n- **Invalid Credit Card Number**: If the `credit-card` field contains a number that cannot be converted to an integer or fails the Luhn check.\n  - Status code: `400 Bad Request`\n  - Example response:\n    ```json\n    {\"error\": \"Invalid credit card number\"}\n    ```\n\n## Customisation\n\n### Changing the Port\n\nBy default, the server listens on port `3333`. You can change this by setting a different value for the `PORT` variable in the [`webserver.go`](https://github.com/ibnaleem/cc-validation-webserver/blob/main/webserver.go) file:\n\n```go\nvar PORT string = \"3333\"\n```\n\nChange `\"3333\"` to any valid port number you prefer (e.g., `\"8080\"`). Note that `PORT` expect a type of `string`, meaning `var PORT string = 8080` is clearly **invalid.** Simply encapsulate the port in quotes `\"\"`. \n\n### Changing the Path\n\nTo customise the root endpoint (`/`) to a different one, modify the `http.HandleFunc` line in the [`webserver.go`](https://github.com/ibnaleem/cc-validation-webserver/blob/main/webserver.go) file:\n\n```go\nhttp.HandleFunc(\"/\", getRoot)\n```\n\nFor example, to change the path to `/validate`, update it as follows:\n\n```go\nhttp.HandleFunc(\"/validate\", getRoot)\n```\n\nNow, the server will expect requests at `http://127.0.0.1:3333/validate`.\n\nTo ensure consistency and avoid confusion, it's best to also update the function name to match the new path. So, if you change the path to `/validate` for example, rename the function to reflect this change:\n\n```go\nfunc getValidate(w http.ResponseWriter, r *http.Request) {...}\n```\n\nAdditionally, update the `fmt.Printf()` to reflect the new path:\n\n```go\nif r.Header.Get(\"Content-Type\") == \"\" {\n    fmt.Printf(\"[%s] on validate (/validate) with cURL\\n\", r.Method)\n} else {\n    fmt.Printf(\"[%s] on validate (/validate) with header %s\\n\", r.Method, r.Header.Get(\"Content-Type\"))\n}\n```\n## License\n\nThis project is licensed under the GNU General Public License - see the [LICENSE](https://github.com/ibnaleem/cc-validation-webserver/blob/main/LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibnaleem%2Fcc-validation-webserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibnaleem%2Fcc-validation-webserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibnaleem%2Fcc-validation-webserver/lists"}