{"id":19358900,"url":"https://github.com/quinta0/httpserver","last_synced_at":"2025-08-02T08:04:58.035Z","repository":{"id":249274258,"uuid":"831070001","full_name":"Quinta0/httpserver","owner":"Quinta0","description":"A very basic HTTP server made in Go","archived":false,"fork":false,"pushed_at":"2024-07-19T15:47:05.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T12:15:26.395Z","etag":null,"topics":["go","golang","http","http-server"],"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/Quinta0.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-07-19T15:33:16.000Z","updated_at":"2024-07-19T17:27:40.000Z","dependencies_parsed_at":"2024-07-19T20:18:03.715Z","dependency_job_id":null,"html_url":"https://github.com/Quinta0/httpserver","commit_stats":null,"previous_names":["quinta0/httpserver"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Quinta0/httpserver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quinta0%2Fhttpserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quinta0%2Fhttpserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quinta0%2Fhttpserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quinta0%2Fhttpserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Quinta0","download_url":"https://codeload.github.com/Quinta0/httpserver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quinta0%2Fhttpserver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268351022,"owners_count":24236329,"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-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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","http-server"],"created_at":"2024-11-10T07:13:28.256Z","updated_at":"2025-08-02T08:04:58.001Z","avatar_url":"https://github.com/Quinta0.png","language":"Go","readme":"# Basic HTTP Server in Go\nThis document explains the functionalities of a basic HTTP server implemented in Go. The server responds to two different routes: `/` and `/hello`.\n\n## Code Overview\n\n### Package and Imports\n\n```go\npackage main\n\nimport (\n    \"errors\"\n    \"fmt\"\n    \"io\"\n    \"net/http\"\n    \"os\"\n)\n```\n\nThe server starts by defining the main package and importing necessary libraries:\n\n- errors: For handling errors.\n- fmt: For formatted I/O operations.\n- io: For basic input and output interfaces.\n- net/http: For HTTP client and server implementations.\n- os: For interacting with the operating system.\n\n### Root Handler\n\n```go\nfunc getRoot(w http.ResponseWriter, r *http.Request) {\n    fmt.Printf(\"Request received: \\n\")\n    io.WriteString(w, \"This is my first web server. \\n\")\n}\n```\nThe getRoot function handles requests to the root URL (/). It prints a message to the console and responds to the client with a simple message.\n\n### Hello Handler\n\n```go\nfunc getHello(w http.ResponseWriter, r *http.Request) {\n    fmt.Printf(\"Hello request received: \\n\")\n    io.WriteString(w, \"Hello, World! \\n\")\n}\n```\nThe getHello function handles requests to the /hello URL. It prints a different message to the console and responds with a \"Hello, World!\" message.\n\n### Main Function\n\n```go\nfunc main() {\n    http.HandleFunc(\"/\", getRoot)\n    http.HandleFunc(\"/hello\", getHello)\n\n    err := http.ListenAndServe(\":8080\", nil)\n    if errors.Is(err, http.ErrServerClosed) {\n        fmt.Printf(\"Server Closed! \\n\")\n    } else if err != nil {\n        fmt.Printf(\"Error: %v \\n\", err)\n        os.Exit(1)\n    }\n    fmt.Printf(\"Server started! \\n\")\n}\n```\nThe main function sets up the HTTP server:\n\n- It registers the getRoot handler for the root URL (/).\n- It registers the getHello handler for the /hello URL.\n- It starts the server on port 8080 using http.ListenAndServe.\n- If the server is closed or an error occurs, appropriate messages are printed, and the program exits with a status code of 1.\n\n### Error Handling\nThe server uses errors.Is to check if the error returned by http.ListenAndServe is http.ErrServerClosed. If a different error occurs, it prints the error and exits the program.\n\n\n## Running the Server\nTo run the server, execute the following command in your terminal:\n    \n```bash\ngo run main.go\n```\n\nThis will start the server on port 8080. You can access the root URL (`http://localhost:8080/`) and the hello URL (`http://localhost:8080/hello`) in your browser or using a tool like CURL.\n```bash\ncurl http://localhost:8080/\ncurl http://localhost:8080/hello\n```\n\nThe server will respond with the following messages for each route:\n- http://localhost:8080/: Displays \"This is my first web server.\"\n- http://localhost:8080/hello: Displays \"Hello, World!\"\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquinta0%2Fhttpserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquinta0%2Fhttpserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquinta0%2Fhttpserver/lists"}