{"id":16915033,"url":"https://github.com/butuzov/mirror","last_synced_at":"2025-04-12T18:50:26.618Z","repository":{"id":46624289,"uuid":"407770377","full_name":"butuzov/mirror","owner":"butuzov","description":"Use right mirror functions for string/[]byte performance bust","archived":false,"fork":false,"pushed_at":"2025-03-24T16:50:37.000Z","size":146,"stargazers_count":44,"open_issues_count":7,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T10:48:32.228Z","etag":null,"topics":["go","liner"],"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/butuzov.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-09-18T05:56:17.000Z","updated_at":"2025-02-17T10:42:36.000Z","dependencies_parsed_at":"2023-12-26T15:45:54.498Z","dependency_job_id":"5c38d93a-3cbc-48c6-b6e4-eb2ffcf54c83","html_url":"https://github.com/butuzov/mirror","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/butuzov%2Fmirror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/butuzov%2Fmirror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/butuzov%2Fmirror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/butuzov%2Fmirror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/butuzov","download_url":"https://codeload.github.com/butuzov/mirror/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618220,"owners_count":21134199,"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":["go","liner"],"created_at":"2024-10-13T19:16:11.464Z","updated_at":"2025-04-12T18:50:26.611Z","avatar_url":"https://github.com/butuzov.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `mirror` [![Stand with Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://u24.gov.ua/) [![Code Coverage](https://coveralls.io/repos/github/butuzov/mirror/badge.svg?branch=main)](https://coveralls.io/github/butuzov/mirror?branch=main) [![build status](https://github.com/butuzov/mirror/actions/workflows/main.yaml/badge.svg?branch=main)]()\n\n`mirror` suggests use of alternative functions/methods in order to gain performance boosts by avoiding unnecessary `[]byte/string` conversion calls. See [MIRROR_FUNCS.md](MIRROR_FUNCS.md) list of mirror functions you can use in go's stdlib.\n\n---\n\n[![United 24](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-personal-page.svg)](https://u24.gov.ua/)\n\n---\n\n## Linter Use Cases\n\n### `github.com/argoproj/argo-cd`\n\n```go\n// Before\nfunc IsValidHostname(hostname string, fqdn bool) bool {\n  if !fqdn {\n    return validHostNameRegexp.Match([]byte(hostname)) || validIPv6Regexp.Match([]byte(hostname))\n  } else {\n    return validFQDNRegexp.Match([]byte(hostname))\n  }\n}\n\n// After: With alternative method (and lost `else` case)\nfunc IsValidHostname(hostname string, fqdn bool) bool {\n  if !fqdn {\n    return validHostNameRegexp.MatchString(hostname) || validIPv6Regexp.MatchString(hostname)\n  }\n\n  return validFQDNRegexp.MatchString(hostname)\n}\n```\n\n## Install\n\n```\ngo install github.com/butuzov/mirror/cmd/mirror@latest\n```\n\n### `golangci-lint`\n`golangci-lint` supports `mirror` since `v1.53.0`\n\n\n## How to use\n\nYou run `mirror` with [`go vet`](https://pkg.go.dev/cmd/vet):\n\n```\ngo vet -vettool=$(which mirror) ./...\n# github.com/jcmoraisjr/haproxy-ingress/pkg/common/net/ssl\npkg/common/net/ssl/ssl.go:64:11: avoid allocations with (*os.File).WriteString\npkg/common/net/ssl/ssl.go:161:12: avoid allocations with (*os.File).WriteString\npkg/common/net/ssl/ssl.go:166:3: avoid allocations with (*os.File).WriteString\n```\n\nCan be called directly:\n```\nmirror ./...\n# https://github.com/cosmtrek/air\n/air/runner/util.go:149:6: avoid allocations with (*regexp.Regexp).MatchString\n/air/runner/util.go:173:14: avoid allocations with (*os.File).WriteString\n```\n\nWith [`golangci-lint`](https://github.com/golangci/golangci-lint)\n\n```\ngolangci-lint run --no-config --disable-all -Emirror\n# github.com/argoproj/argo-cd\ntest/e2e/fixture/app/actions.go:83:11: avoid allocations with (*os.File).WriteString (mirror)\n\t_, err = tmpFile.Write([]byte(data))\n\t         ^\nserver/server.go:1166:9: avoid allocations with (*regexp.Regexp).MatchString (mirror)\n\treturn mainJsBundleRegex.Match([]byte(filename))\n\t       ^\nserver/account/account.go:91:6: avoid allocations with (*regexp.Regexp).MatchString (mirror)\n\tif !validPasswordRegexp.Match([]byte(q.NewPassword)) {\n\t    ^\nserver/badge/badge.go:52:20: avoid allocations with (*regexp.Regexp).FindAllStringSubmatchIndex (mirror)\n\tfor _, v := range re.FindAllSubmatchIndex([]byte(str), -1) {\n\t                  ^\nutil/cert/cert.go:82:10: avoid allocations with (*regexp.Regexp).MatchString (mirror)\n\t\treturn validHostNameRegexp.Match([]byte(hostname)) || validIPv6Regexp.Match([]byte(hostname))\n```\n\n## Command line\n\n- You can add checks for `_test.go` files with cli option `--with-tests`\n\n### `golangci-lint`\n  With `golangci-lint` tests are checked by default and can be can be turned off by using the regular `golangci-lint` ways to do it:\n\n  - flag `--tests` (e.g. `--tests=false`)\n  - flag `--skip-files` (e.g. `--skip-files=\"_test.go\"`)\n  - yaml configuration `run.skip-files`:\n    ```yaml\n    run:\n      skip-files:\n        - '(.+)_test\\.go'\n    ```\n  - yaml configuration `issues.exclude-rules`:\n    ```yaml\n      issues:\n        exclude-rules:\n          - path: '(.+)_test\\.go'\n            linters:\n              - mirror\n      ```\n\n\n## Contributing\n\n```shell\n# Update Assets (testdata/(strings|bytes|os|utf8|maphash|regexp|bufio).go)\n(task|make) generate\n# Run Tests\n(task|make) tests\n# Lint Code\n(task|make) lints\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbutuzov%2Fmirror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbutuzov%2Fmirror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbutuzov%2Fmirror/lists"}