{"id":34192756,"url":"https://github.com/cosiner/go-schema","last_synced_at":"2026-03-09T23:35:41.712Z","repository":{"id":57490172,"uuid":"160954573","full_name":"cosiner/go-schema","owner":"cosiner","description":null,"archived":false,"fork":false,"pushed_at":"2018-12-23T15:06:57.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-13T23:47:09.076Z","etag":null,"topics":["binding","form","go","http","schema"],"latest_commit_sha":null,"homepage":null,"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/cosiner.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":"2018-12-08T15:56:47.000Z","updated_at":"2021-12-10T07:42:50.000Z","dependencies_parsed_at":"2022-09-02T12:01:28.628Z","dependency_job_id":null,"html_url":"https://github.com/cosiner/go-schema","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/cosiner/go-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fgo-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fgo-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fgo-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fgo-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cosiner","download_url":"https://codeload.github.com/cosiner/go-schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosiner%2Fgo-schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30316772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T20:05:46.299Z","status":"ssl_error","status_checked_at":"2026-03-09T19:57:04.425Z","response_time":61,"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":["binding","form","go","http","schema"],"created_at":"2025-12-15T16:23:52.282Z","updated_at":"2026-03-09T23:35:41.703Z","avatar_url":"https://github.com/cosiner.png","language":"Go","readme":"# go-schema\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/cosiner/go-schema) \n[![Build Status](https://travis-ci.org/cosiner/go-schema.svg?branch=master\u0026style=flat)](https://travis-ci.org/cosiner/go-schema)\n[![Coverage Status](https://coveralls.io/repos/github/cosiner/go-schema/badge.svg?style=flat)](https://coveralls.io/github/cosiner/go-schema)\n[![Go Report Card](https://goreportcard.com/badge/github.com/cosiner/go-schema?style=flat)](https://goreportcard.com/report/github.com/cosiner/go-schema)\n\ngo-schema is a simple library for go to bind source strings into structures, inspired by [gorilla/schema](https://github.com/gorilla/schema).\n\n# Install\n```bash\ngo get github.com/cosiner/go-schema\n``` \n# Features\n* implements builtin data types for almost all go primitive types: bool,string,int(8,16,32,64), uint, float...\n* support slice\n* support custom data type by implements specified interface\n* support multiple data source such as url query params, path params, headers, and so on. user can add their own sources\n  by implements specified interface.\n* support anonymous embed structure, structure field, inline structure  \n\n# FieldTags\n```Go\n// format: sources[;flags], sources: source[,source]*, flags: [inline]\ntype FieldOptions struct {\n\tSources []string\n\tInline  bool // for structure field\n}\n```\nEach source can have it's own name, if not specified, use name of first source or converted field name by default.\n\n# Example\n```Go\n\ntype httpRequestSource struct {\n\treq *http.Request\n}\n\nfunc (h *httpRequestSource) Get(source, name string) []string {\n\tswitch source {\n\tcase \"body\":\n\t\t_ = h.req.ParseForm()\n\t\treturn h.req.PostForm[name]\n\tcase \"query\":\n\t\treturn h.req.URL.Query()[name]\n\tcase \"header\":\n\t\treturn h.req.Header[name]\n\tdefault:\n\t\treturn nil\n\t}\n}\n\ntype DateType struct{}\n\nfunc (DateType) DataType() interface{} { return time.Time{} }\n\nfunc (DateType) Decode(s string) (val interface{}, err error) {\n\tt, err := time.Parse(\"2006/01/02\", s)\n\tif err != nil {\n\t\treturn t, err\n\t}\n\treturn t, nil\n}\n\nfunc (DateType) Encode(val interface{}) (s string, err error) {\n\tv, ok := val.(time.Time)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"invalid data type, expect time.Time, but got %s\", reflect.TypeOf(val))\n\t}\n\treturn v.Format(\"2006/01/02\"), nil\n}\n\nfunc newDecoder() (*schema.Decoder, error) {\n\tp, err := schema.NewParser(\"schema\", []string{\"body\", \"query\", \"header\"}, func(name string) string {\n\t\tif name == \"\" {\n\t\t\treturn \"\"\n\t\t}\n\t\treturn strings.ToLower(name[:1]) + name[1:]\n\t})\n\tif err == nil {\n\t\terr = p.RegisterTypes(schema.BuiltinTypes()...)\n\t}\n\tif err == nil {\n\t\terr = p.RegisterTypes(DateType{})\n\t}\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn schema.NewDecoder(p)\n}\n\nfunc ExampleDecoder_Decode() {\n\ttype QueryRequest struct {\n\t\tName        string    `schema:\"body\"`\n\t\tDate        time.Time `schema:\"body\"`\n\t\tAccessToken string    `schema:\"header\" header:\"Authorization\"`\n\t\tPage        uint32    `schema:\"query\" query:\"p\"`\n\t}\n\tu, err := url.Parse(\"http://localhost?p=3\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\thttpreq := http.Request{\n\t\tURL: u,\n\t\tPostForm: url.Values{\n\t\t\t\"name\": []string{\"Someone\"},\n\t\t\t\"date\": []string{\"2018/12/25\"},\n\t\t},\n\t\tHeader: http.Header{\n\t\t\t\"Authorization\": []string{\"Token\"},\n\t\t},\n\t}\n\td, err := newDecoder()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tvar reqData QueryRequest\n\terr = d.Decode(\u0026httpRequestSource{\u0026httpreq}, \u0026reqData)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Printf(\"%s %s %s %d\\n\", reqData.Name, reqData.Date.Format(\"2006-01-02\"), reqData.AccessToken, reqData.Page)\n\t// Output: Someone 2018-12-25 Token 3\n}\n\n```\n\n# License\nMIT.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosiner%2Fgo-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosiner%2Fgo-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosiner%2Fgo-schema/lists"}