{"id":18418576,"url":"https://github.com/bsm/conditional","last_synced_at":"2025-04-13T05:54:53.781Z","repository":{"id":57514769,"uuid":"240069747","full_name":"bsm/conditional","owner":"bsm","description":"Conditional HTTP responses with Go","archived":false,"fork":false,"pushed_at":"2020-02-27T13:49:00.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T05:54:50.606Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsm.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":"2020-02-12T17:14:09.000Z","updated_at":"2020-04-15T07:56:30.000Z","dependencies_parsed_at":"2022-09-26T18:00:55.456Z","dependency_job_id":null,"html_url":"https://github.com/bsm/conditional","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fconditional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fconditional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fconditional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Fconditional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsm","download_url":"https://codeload.github.com/bsm/conditional/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248670502,"owners_count":21142901,"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":[],"created_at":"2024-11-06T04:14:03.673Z","updated_at":"2025-04-13T05:54:53.750Z","avatar_url":"https://github.com/bsm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Conditional\n\n[![Build Status](https://travis-ci.org/bsm/conditional.png?branch=master)](https://travis-ci.org/bsm/conditional)\n[![GoDoc](https://godoc.org/github.com/bsm/conditional?status.png)](http://godoc.org/github.com/bsm/conditional)\n[![Go Report Card](https://goreportcard.com/badge/github.com/bsm/conditional)](https://goreportcard.com/report/github.com/bsm/conditional)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nConditional HTTP helpers for [Go](https://golang.org) stdlib's [net/http](https://golang.org/pkg/net/http) package.\n\nSupported headers:\n\n* `If-Match`\n* `If-None-Match`\n* `If-Modified-Since`\n* `If-Unmodified-Since`\n\n## Example:\n\n```go\nimport(\n\t\"fmt\"\n\t\"net/http\"\n\t\"net/http/httptest\"\n\n\t\"github.com/bsm/conditional\"\n)\n\nfunc main() {\n\tsrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\t// set ETag and/or Last-Modified headers\n\t\tw.Header().Set(\"ETag\", `\"strong\"`)\n\t\tw.Header().Set(\"Last-Modified\", \"Fri, 05 Jan 2018 11:25:15 GMT\")\n\n\t\t// perform conditional check\n\t\tif conditional.Check(w, r) {\n\t\t\treturn\n\t\t}\n\t\tw.WriteHeader(http.StatusNoContent)\n\t}))\n\tdefer srv.Close()\n\n\tclient := new(http.Client)\n\n\t// make a plain GET request\n\treq, err := http.NewRequest(\"GET\", srv.URL, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tres, err := client.Do(req)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(res.Status)\t// =\u003e 204 No Content\n\n\t// now, try it with a matchingg \"If-Modified-Since\"\n\treq, err = http.NewRequest(\"GET\", srv.URL, nil)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treq.Header.Set(\"If-Modified-Since\", \"Fri, 05 Jan 2018 11:25:15 GMT\")\n\tres, err = client.Do(req)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(res.Status)\t// =\u003e 304 Not Modified\n\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsm%2Fconditional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsm%2Fconditional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsm%2Fconditional/lists"}