{"id":25121880,"url":"https://github.com/aidenwallis/go-write","last_synced_at":"2026-02-28T13:08:56.272Z","repository":{"id":56805082,"uuid":"524277953","full_name":"aidenwallis/go-write","owner":"aidenwallis","description":"Simple, clean Golang HTTP response writer.","archived":false,"fork":false,"pushed_at":"2022-08-13T02:46:26.000Z","size":11,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T04:03:36.490Z","etag":null,"topics":["golang","http","response-writer"],"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/aidenwallis.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}},"created_at":"2022-08-13T02:23:08.000Z","updated_at":"2024-12-28T07:31:31.000Z","dependencies_parsed_at":"2022-08-17T09:30:32.447Z","dependency_job_id":null,"html_url":"https://github.com/aidenwallis/go-write","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/aidenwallis/go-write","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fgo-write","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fgo-write/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fgo-write/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fgo-write/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aidenwallis","download_url":"https://codeload.github.com/aidenwallis/go-write/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aidenwallis%2Fgo-write/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29935036,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T13:00:17.143Z","status":"ssl_error","status_checked_at":"2026-02-28T12:59:13.669Z","response_time":90,"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":["golang","http","response-writer"],"created_at":"2025-02-08T06:37:47.446Z","updated_at":"2026-02-28T13:08:56.240Z","avatar_url":"https://github.com/aidenwallis.png","language":"Go","readme":"# go-write\n\n[![codecov](https://codecov.io/gh/aidenwallis/go-write/branch/main/graph/badge.svg?token=BQOADNY183)](https://codecov.io/gh/aidenwallis/go-write) [![Go Reference](https://pkg.go.dev/badge/github.com/aidenwallis/go-write.svg)](https://pkg.go.dev/github.com/aidenwallis/go-write)\n\nA simple, clean HTTP response builder for [net/http](https://pkg.go.dev/net/http). This package is deliberately very light, and simple. There are no external dependencies, just a really clean way to write handlers.\n\n## Usage\n\nYou may interact with this package using the builder, or the code-generated functions. They behave the same.\n\nThe code-generated functions simply call the builder for you, they're just there for your convenience.\n\n### Response types\n\nThere are 4 different ways you can currently end responses with go-write.\n\n#### Bytes\n\nYou may send raw bytes using go-write, it will simply copy the bytes ot the body, and send your HTTP status code with a `Content-Length` header:\n\n```go\nerr := write.New(w, http.StatusTeapot).Bytes([]byte(\"abc123\"))\n```\n\n#### Empty\n\nYou may send empty responses using go-write, the body will be empty, and will only send a HTTP status code:\n\n```go\nerr := write.New(w, http.StatusTeapot).Empty()\n```\n\n#### JSON\n\n**`Content-Type`: `application/json; charset=utf-8`**\n\nYou may send JSON responses using go-write, the body will be marshalled JSON, it will set the corresponding `Content-Type` and `Content-Length` header, and send your HTTP status code:\n\n```go\n\ntype myBody struct {\n    Key string `json:\"key\"`\n    Value string `json:\"value\"`\n}\n\nerr := write.New(w, http.StatusTeapot).JSON(\u0026myBody{\n    Key:   \"foo\",\n    Value: \"bar\",\n})\n```\n\n#### Text\n\n**`Content-Type`: `text/plain; charset=utf-8`**\n\nYou may send plain text responses using go-write, it will simply copy the text to the body, set the `Content-Type` and `Content-Length` header, and send your HTTP status code:\n\n```go\nerr := write.New(w, http.StatusTeapot).Text(\"example text!\")\n```\n\n### Using the builder\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"net/http\"\n\t\"os\"\n\t\"os/signal\"\n\t\"syscall\"\n\n\t\"github.com/aidenwallis/go-write/write\"\n)\n\nfunc main() {\n\tsrv := \u0026http.Server{\n\t\tAddr: \":1234\",\n\t\tHandler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {\n\t\t\tif err := write.New(w, http.StatusTeapot).Text(\"This handler is indeed a teapot...\"); err != nil {\n\t\t\t\tlog.Println(\"Failed to handle HTTP response: \" + err.Error())\n\t\t\t}\n\t\t}),\n\t}\n\tdefer srv.Shutdown(context.Background())\n\n\tgo func() {\n\t\tlog.Println(\"Server running.\")\n\t\t_ = srv.ListenAndServe()\n\t}()\n\n\tc := make(chan os.Signal, 1)\n\tsignal.Notify(c, syscall.SIGINT, syscall.SIGTERM)\n\t\u003c-c\n}\n```\n\n### Using the code-generated functions\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"net/http\"\n\t\"os\"\n\t\"os/signal\"\n\t\"syscall\"\n\n\t\"github.com/aidenwallis/go-write/write\"\n)\n\nfunc main() {\n\tsrv := \u0026http.Server{\n\t\tAddr: \":1234\",\n\t\tHandler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {\n\t\t\tif err := write.Teapot(w).Text(\"This handler is indeed a teapot...\"); err != nil {\n\t\t\t\tlog.Println(\"Failed to handle HTTP response: \" + err.Error())\n\t\t\t}\n\t\t}),\n\t}\n\tdefer srv.Shutdown(context.Background())\n\n\tgo func() {\n\t\tlog.Println(\"Server running.\")\n\t\t_ = srv.ListenAndServe()\n\t}()\n\n\tc := make(chan os.Signal, 1)\n\tsignal.Notify(c, syscall.SIGINT, syscall.SIGTERM)\n\t\u003c-c\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faidenwallis%2Fgo-write","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faidenwallis%2Fgo-write","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faidenwallis%2Fgo-write/lists"}