{"id":16304772,"url":"https://github.com/moznion/taqc","last_synced_at":"2025-03-22T19:35:02.810Z","repository":{"id":38974428,"uuid":"436149637","full_name":"moznion/taqc","owner":"moznion","description":"Tag based url Query parameters Constructor.","archived":false,"fork":false,"pushed_at":"2025-03-05T21:38:18.000Z","size":38,"stargazers_count":2,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T14:15:44.675Z","etag":null,"topics":["golang","query-parameters"],"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/moznion.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":"2021-12-08T07:05:38.000Z","updated_at":"2022-01-11T10:38:34.000Z","dependencies_parsed_at":"2022-09-07T04:12:11.576Z","dependency_job_id":"dfa9978a-e65b-4676-89bb-6d75bc1a883f","html_url":"https://github.com/moznion/taqc","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":0.12,"last_synced_commit":"e1130d0a0ccc9c144e0114760250f96dc3859bca"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Ftaqc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Ftaqc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Ftaqc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moznion%2Ftaqc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moznion","download_url":"https://codeload.github.com/moznion/taqc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245013747,"owners_count":20547175,"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":["golang","query-parameters"],"created_at":"2024-10-10T21:04:46.692Z","updated_at":"2025-03-22T19:35:02.291Z","avatar_url":"https://github.com/moznion.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# taqc 🚕 [![.github/workflows/check.yml](https://github.com/moznion/taqc/actions/workflows/check.yml/badge.svg)](https://github.com/moznion/taqc/actions/workflows/check.yml) [![codecov](https://codecov.io/gh/moznion/taqc/branch/main/graph/badge.svg?token=NU9ZSW4ZL9)](https://codecov.io/gh/moznion/taqc)\n\n\u003cb\u003eTa\u003c/b\u003eg based url \u003cb\u003eQ\u003c/b\u003euery parameters \u003cb\u003eC\u003c/b\u003eonstructor.  \n(This is pronounced as same as \"taxi\")\n\n## Synopsis\n\n```go\ntype Query struct {\n\tFoo             string    `taqc:\"foo\"`\n\tBar             *string   `taqc:\"bar\"`\n\tBuz             int64     `taqc:\"buz\"`\n\tQux             []float64 `taqc:\"qux\"`\n\tFooBar          bool      `taqc:\"foobar\"`\n\tFalsy           bool      `taqc:\"falsy\"`\n\tShouldBeIgnored string\n}\n\nqueryParams, err := taqc.ConvertToQueryParams(\u0026Query{\n\tFoo:             \"string_value\",\n\tBar:             nil, // \u003c= should be ignored\n\tBuz:             123,\n\tQux:             []float64{123.456, 234.567},\n\tFooBar:          true,  // \u003c= be \"foobar=1\"\n\tFalsy:           false, // \u003c= should be ignored\n\tShouldBeIgnored: \"should be ignored\",\n})\nif err != nil {\n\tpanic(err)\n}\n\nfmt.Printf(\"%s\\n\", queryParams.Encode())\n\n// Output:\n// buz=123\u0026foo=string_value\u0026foobar=1\u0026qux=123.456000\u0026qux=234.567000\n```\n\n## Requirements\n\n- Go 1.17 or later\n\n## Description\n\n[![GoDoc](https://godoc.org/github.com/moznion/taqc?status.svg)](https://godoc.org/github.com/moznion/taqc)\n\nThis library constructs the query parameters (i.e. `url.Value{}`) according to the struct, and the `taqc` tag which is in each field.\n\nCurrently, it supports the following field types: `string`, `int64`, `float64`, `bool`, `*string`, `*int64`, `*float64`, `*bool`, `[]string`, `[]int64`, `[]float64`, `time.Time`, `*time.Time`, and `[]time.Time`.\n\nIf the bool field is `true`, the query parameter becomes `param_name=1`. Else, it omits the parameter.\n\nAnd, when the pointer value is `nil`, it omits the parameter.\n\n### `time.Time` field\n\nThis library supports the `time.Time` fields. By default, it encodes that timestamp by `Time#Unix()`.\n\nIf you want to encode it by another unix time format, you can use `unixTimeUnit` custom tag value.\nFor example:\n\n```go\ntype Query struct {\n\tFoo time.Time `taqc:\"foo, unixTimeUnit=millisec\"`\n}\n```\n\nin the case of the above example, it encodes the timestamp by `Time#UnixMilli()`.\n\nCurrently `unixTimeUnit` supports the following values:\n\n- `sec`\n- `millisec`\n- `microsec`\n- `nanosec`\n\nIt also supports encoding with arbitrary time layout by `timeLayout` custom tag value. e.g.\n\n```go\ntype Query struct {\n\tFoo time.Time `taqc:\"foo, timeLayout=2006-01-02T15:04:05Z07:00\"` // RFC3339 layout\n}\n```\n\nthen, it encodes the timestamp by `Time#Format()` with given layout.\n\nNOTE: `timeLayout` takes priority over `unixTimeUnit`. This means it uses `timeLayout` option even if you put them together.\n\n## Command-line Tool\n\nThis library also provides a command-line tool to generate code.\n\n`taqc.ConvertToQueryParams()` converts the given struct value to query parameters by using reflection dynamically,\nbut this way has a little disadvantage from the performance perspective.\n\nThis CLI tool generates the code statically, and this can convert that structure to the query parameters more efficiently.\n\n### Installation\n\n```\ngo install github.com/moznion/taqc/cmd/taqc@latest\n```\n\nAnd you can grab a pre-built binary here: https://github.com/moznion/taqc/releases\n\n### Usage\n\n```\nUsage of taqc:\n  -type string\n        [mandatory] a type name\n  -output string\n        [optional] output file name (default \"srcdir/\u003ctype\u003e_gen.go\")\n  -version\n        show the version information\n```\n\n### Example\n\nWhen it has the following code:\n\n```go\n//go:generate taqc --type=QueryParam\ntype QueryParam struct {\n\tFoo             string  `taqc:\"foo\"`\n\tBar             int64   `taqc:\"bar\"`\n\tBuz             float64 `taqc:\"buz\"`\n\tQux             bool    `taqc:\"qux\"`\n}\n```\n\nthen you run `go generate ./...`, it generates code on `query_param_gen.go` that is in the same directory of the original struct file. That generated file has a method `(v *QueryParam) ToQueryParameters() url.Values`.\n\n## Author\n\nmoznion (\u003cmoznion@mail.moznion.net\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Ftaqc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoznion%2Ftaqc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoznion%2Ftaqc/lists"}