{"id":37208469,"url":"https://github.com/orian/wrapgen","last_synced_at":"2026-01-14T23:58:26.967Z","repository":{"id":57544964,"uuid":"297744940","full_name":"orian/wrapgen","owner":"orian","description":"Interface wrapper generator for Go","archived":false,"fork":true,"pushed_at":"2020-09-27T00:05:39.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-13T02:36:50.461Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"kevinconway/wrapgen","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orian.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-09-22T19:00:32.000Z","updated_at":"2020-09-22T20:28:35.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/orian/wrapgen","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/orian/wrapgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orian%2Fwrapgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orian%2Fwrapgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orian%2Fwrapgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orian%2Fwrapgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orian","download_url":"https://codeload.github.com/orian/wrapgen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orian%2Fwrapgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28439595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"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":[],"created_at":"2026-01-14T23:58:26.360Z","updated_at":"2026-01-14T23:58:26.958Z","avatar_url":"https://github.com/orian.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Hard fork of [github.com/kevinconway/wrapgen](https://github.com/kevinconway/wrapgen).\n\n# wrapgen - A code generator for Go interfaces\n\nThis project can inject the details of any Go interface into a custom template.\nThe goal is to enable teams who either make frequent use of interface wrappers\nto layer on behavior, such as using a decorator pattern, or teams who often need\nto generate standard implementations of some interfaces, such as those genrating\nstubs for a test.\n\nThis project is heavily inspired by \u003chttps://github.com/golang/mock\u003e which\ncontains a tool called `mockgen` that can generate an advanced mock\nimplementation of any Go interface.\n\n## Usage\n\n### Quick Example\n\n```bash\ngo install github.com/orian/wrapgen\ngo install golang.org/x/tools/cmd/goimports\n\n${GOPATH}/bin/wrapgen \\\n  --source=io \\\n  --interface=Reader \\\n  --interface=Writer \\\n  --package=wrappers \\\n  --template=\"https://github.com/orian/wrapgen/templates/logtime.txt\" \\\n  | ${GOPATH}/bin/goimports\n```\n\nThe output will look like:\n\n```golang\npackage wrappers\n// Code generated by wrapgen DO NOT EDIT\n\nimport (\n        \"io\"\n        \"log\"\n        \"time\"\n)\n\ntype WrapsReader struct {\n        wrapped io.Reader\n}\n\nfunc (w *WrapsReader) Read(p []byte) (int, error) {\n        start := time.Now()\n        defer func() {\n                log.Println(\"Read latency:\", time.Now().Since(start))\n        }()\n        var n, err = w.wrapped.Read(p)\n        return n, err\n}\n\ntype WrapsWriter struct {\n        wrapped io.Writer\n}\n\nfunc (w *WrapsWriter) Write(p []byte) (int, error) {\n        start := time.Now()\n        defer func() {\n                log.Println(\"Write latency:\", time.Now().Since(start))\n        }()\n        var n, err = w.wrapped.Write(p)\n        return n, err\n}\n```\n\nAll output is written to `stdout` and `stderr`. Template paths may either be\nURLs or file system paths. It is highly suggested to use `goimports` or another\nformatter as a post-processor.\n\n### CLI Options\n\n```bash\nwrapgen --help\n\nUsage of wrapgen:\n      --interface strings   The name of the interface to render.\n      --leftdelim string    Left-hand side delimiter for the template. (default \"#!\")\n      --package string      The package name that the resulting file will be in. Defaults to the source package.\n      --rightdelim string   Right-hand side delimiter for the template. (default \"!#\")\n      --source string       The import path of the package to render.\n      --template string     The template to render.\n      --timeout duration    Maximum runtime allowed for rendering. (default 1m0s)\n```\n\nAny number of interfaces may be given by providing more `--interface` flags.\n\n### Writing Templates\n\nThe `templates/basic.txt` template from this project is the best way to get\nstarted writing your own. It demonstrates the how to manage import statements,\niterate over the collected interfaces, and already covers the complexity of\nrendering method arguments and outputs correctly.\n\nWhether using `template/basics.txt` as a starter or generating a new template\nfrom scratch, the template content must be valid `text/template` markup. By\ndefault, the character sets `#!` and `!#` are used as the left and right\ndelimiters, respectively. Those characters are the default because they rarely,\nif ever, conflict with common character sets in Go code. You can adjust these\nwith CLI flags.\n\nThe root context injected into the template is `Package` from the following:\n\n```golang\n// Package is a container for all exported interfaces of a Go package.\ntype Package struct {\n\tName       string\n\tSource     *Import\n\tInterfaces []*Interface\n\tImports    []*Import\n}\n\n// Import is a package name and path that is imported by another package.\ntype Import struct {\n\tPackage string\n\tPath    string\n}\n\n// Interface is an exported interface defined in a package.\ntype Interface struct {\n\tSrcType Type\n\tName    string\n\tMethods []*Method\n}\n\n// Method is a named function attached to an interface.\ntype Method struct {\n\tName string\n\tIn   []*Parameter\n\tOut  []*Parameter\n}\n\n// Parameter is a named parameter used by a Method.\ntype Parameter struct {\n\tName string\n\tType Type\n}\n\n// Type is a Go type definition that can be rendered into a valid\n// Go code snippet.\ntype Type interface {\n\tString() string\n}\n```\n\nThose are the structures available within any template. Each `Type` is\nspecialized and will render correctly when calling `String()`. For example, a\n`Parameter` with `Type` of read-only channel of integers will render as `\u003c-chan\nint` when calling `String()` on the type. The `templates/basic.txt` template\ncontains examples of inspecting the type string in order to support variadics.\nThis practice can be extended to, for example, determine if the first parameter\nis a context and optionall fetch a value from it.\n\n## License\n\nThis project is available under the Apache2.0 license. See the `LICENSE` file\nin this repository for the complete license text.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forian%2Fwrapgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forian%2Fwrapgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forian%2Fwrapgen/lists"}