{"id":13412973,"url":"https://github.com/rjeczalik/interfaces","last_synced_at":"2025-04-07T14:11:01.254Z","repository":{"id":42976469,"uuid":"47477512","full_name":"rjeczalik/interfaces","owner":"rjeczalik","description":"Code generation tools for Go.","archived":false,"fork":false,"pushed_at":"2024-09-08T16:13:26.000Z","size":56,"stargazers_count":421,"open_issues_count":13,"forks_count":32,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-09-08T18:11:33.226Z","etag":null,"topics":["codegen","golang","golang-interface","golang-package"],"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/rjeczalik.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":"2015-12-06T00:04:50.000Z","updated_at":"2024-09-08T16:13:29.000Z","dependencies_parsed_at":"2022-07-13T23:00:30.154Z","dependency_job_id":"c2eec052-6304-4678-9651-d33785a91d8d","html_url":"https://github.com/rjeczalik/interfaces","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjeczalik%2Finterfaces","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjeczalik%2Finterfaces/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjeczalik%2Finterfaces/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rjeczalik%2Finterfaces/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rjeczalik","download_url":"https://codeload.github.com/rjeczalik/interfaces/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247666008,"owners_count":20975787,"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":["codegen","golang","golang-interface","golang-package"],"created_at":"2024-07-30T20:01:31.777Z","updated_at":"2025-04-07T14:11:01.225Z","avatar_url":"https://github.com/rjeczalik.png","language":"Go","funding_links":[],"categories":["Generation and Generics","Generators","发电机","Go","代碼生成與泛型","代码生成与泛型","Generation \u0026 Generics","\u003cspan id=\"代和泛型-generation-and-generics\"\u003e代和泛型 Generation and Generics\u003c/span\u003e","Relational Databases"],"sub_categories":["Advanced Console UIs","Search and Analytic Databases","检索及分析资料库","高級控制台界面","Utility/Miscellaneous","SQL 查询语句构建库","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高级控制台界面"],"readme":"# interfaces [![GoDoc](https://godoc.org/github.com/rjeczalik/interfaces?status.png)](https://godoc.org/github.com/rjeczalik/interfaces) [![Build Status](https://img.shields.io/travis/rjeczalik/interfaces/master.svg)](https://travis-ci.org/rjeczalik/interfaces \"linux_amd64\") [![Build status](https://img.shields.io/appveyor/ci/rjeczalik/interfaces.svg)](https://ci.appveyor.com/project/rjeczalik/interfaces \"windows_amd64\")\nCode generation tools for Go's interfaces.\n\nTools available in this repository:\n\n- [cmd/interfacer](#cmdinterfacer-)\n- [cmd/structer](#cmdstructer-)\n\n### cmd/interfacer [![GoDoc](https://godoc.org/github.com/rjeczalik/interfaces/cmd/interfacer?status.png)](https://godoc.org/github.com/rjeczalik/interfaces/cmd/interfacer)\n\nGenerates an interface for a named type.\n\n*Installation*\n```bash\n~ $ go install github.com/rjeczalik/interfaces/cmd/interfacer@latest\n```\n\n*Usage*\n\n```bash\n~ $ interfacer -help\n```\n```\nUsage of interfacer:\n  -all\n        Include also unexported methods.\n  -as string\n        Generated interface name. (default \"main.Interface\")\n  -for string\n        Type to generate an interface for.\n  -o string\n        Output file. (default \"-\")\n```\n\n*Example*\n- generate by manually\n```bash\n~ $ interfacer -for os.File -as mock.File\n```\n- generate by go generate\n```go\n//go:generate interfacer -for os.File -as mock.File -o file_iface.go\n```\n```bash\n~ $ go generate  ./...\n```\n- output\n```go\n// Created by interfacer; DO NOT EDIT\n\npackage mock\n\nimport (\n        \"os\"\n)\n\n// File is an interface generated for \"os\".File.\ntype File interface {\n        Chdir() error\n        Chmod(os.FileMode) error\n        Chown(int, int) error\n        Close() error\n        Fd() uintptr\n        Name() string\n        Read([]byte) (int, error)\n        ReadAt([]byte, int64) (int, error)\n        Readdir(int) ([]os.FileInfo, error)\n        Readdirnames(int) ([]string, error)\n        Seek(int64, int) (int64, error)\n        Stat() (os.FileInfo, error)\n        Sync() error\n        Truncate(int64) error\n        Write([]byte) (int, error)\n        WriteAt([]byte, int64) (int, error)\n        WriteString(string) (int, error)\n}\n```\n\n### cmd/structer [![GoDoc](https://godoc.org/github.com/rjeczalik/interfaces/cmd/structer?status.png)](https://godoc.org/github.com/rjeczalik/interfaces/cmd/structer)\n\nGenerates a struct for a formatted file. Currently supported formats are:\n\n- CSV\n\n*Installation*\n```bash\n~ $ go get github.com/rjeczalik/interfaces/cmd/structer\n```\n\n*Usage*\n\n```bash\n~ $ structer -help\n```\n```\nUsage of structer:\n  -as string\n        Generated struct name. (default \"main.Struct\")\n  -f string\n        Input file. (default \"-\")\n  -o string\n        Output file. (default \"-\")\n  -tag string\n        Name for a struct tag to add to each field.\n  -type string\n        Type of the input, overwrites inferred from file name.\n```\n\n*Example*\n\n```bash\n~ $ head -2 aws-billing.csv         # first line is a CSV header, second - first line of values\n```\n```\n\"InvoiceID\",\"PayerAccountId\",\"LinkedAccountId\",\"RecordType\",\"RecordID\",\"BillingPeriodStartDate\",\"BillingPeriodEndDate\",\"InvoiceDate\"\n\"Estimated\",\"123456\",\"\",\"PayerLineItem\",\"5433212345\",\"2016/01/01 00:00:00\",\"2016/01/31 23:59:59\",\"2016/01/21 19:19:06\"\n```\n```bash\n~ $ structer -f aws-billing.csv -tag json -as billing.Record\n```\n```go\n// Created by structer; DO NOT EDIT\n\npackage billing\n\nimport (\n        \"strconv\"\n        \"time\"\n)\n\n// Record is a struct generated from \"aws-billing.csv\" file.\ntype Record struct {\n        InvoiceID              string    `json:\"invoiceID\"`\n        PayerAccountID         int64     `json:\"payerAccountID\"`\n        LinkedAccountID        string    `json:\"linkedAccountID\"`\n        RecordType             string    `json:\"recordType\"`\n        RecordID               int64     `json:\"recordID\"`\n        BillingPeriodStartDate time.Time `json:\"billingPeriodStartDate\"`\n        BillingPeriodEndDate   time.Time `json:\"billingPeriodEndDate\"`\n        InvoiceDate            time.Time `json:\"invoiceDate\"`\n}\n\n// MarshalCSV encodes r as a single CSV record.\nfunc (r *Record) MarshalCSV() ([]string, error) {\n        records := []string{\n                r.InvoiceID,\n                strconv.FormatInt(r.PayerAccountID, 10),\n                r.LinkedAccountID,\n                r.RecordType,\n                strconv.FormatInt(r.RecordID, 10),\n                time.Parse(\"2006/01/02 15:04:05\", r.BillingPeriodStartDate),\n                time.Parse(\"2006/01/02 15:04:05\", r.BillingPeriodEndDate),\n                time.Parse(\"2006/01/02 15:04:05\", r.InvoiceDate),\n        }\n        return records, nil\n}\n\n// UnmarshalCSV decodes a single CSV record into r.\nfunc (r *Record) UnmarshalCSV(record []string) error {\n        if len(record) != 8 {\n                return fmt.Errorf(\"invalud number fields: want 8, got %d\", len(record))\n        }\n        r.InvoiceID = record[0]\n        if record[1] != \"\" {\n                if val, err := strconv.ParseInt(record[1], 10, 64); err == nil {\n                        r.PayerAccountID = val\n                } else {\n                        return err\n                }\n        }\n        r.LinkedAccountID = record[2]\n        r.RecordType = record[3]\n        if record[4] != \"\" {\n                if val, err := strconv.ParseInt(record[4], 10, 64); err == nil {\n                        r.RecordID = val\n                } else {\n                        return err\n                }\n        }\n        if record[5] != \"\" {\n                if val, err := time.Parse(\"2006/01/02 15:04:05\", record[5]); err == nil {\n                        r.BillingPeriodStartDate = val\n                } else {\n                        return err\n                }\n        }\n        if record[6] != \"\" {\n                if val, err := time.Parse(\"2006/01/02 15:04:05\", record[6]); err == nil {\n                        r.BillingPeriodEndDate = val\n                } else {\n                        return err\n                }\n        }\n        if record[7] != \"\" {\n                if val, err := time.Parse(\"2006/01/02 15:04:05\", record[7]); err == nil {\n                        r.InvoiceDate = val\n                } else {\n                        return err\n                }\n        }\n        return nil\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjeczalik%2Finterfaces","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frjeczalik%2Finterfaces","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frjeczalik%2Finterfaces/lists"}