{"id":13564525,"url":"https://github.com/rocketlaunchr/igo","last_synced_at":"2025-04-12T19:32:33.870Z","repository":{"id":57481737,"uuid":"157954180","full_name":"rocketlaunchr/igo","owner":"rocketlaunchr","description":"Improved Go Syntax (transpiler)","archived":false,"fork":false,"pushed_at":"2020-04-06T07:25:36.000Z","size":72,"stargazers_count":67,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T06:55:33.868Z","etag":null,"topics":["go","golang"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rocketlaunchr.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-11-17T05:34:03.000Z","updated_at":"2025-02-17T20:19:18.000Z","dependencies_parsed_at":"2022-09-02T06:10:17.633Z","dependency_job_id":null,"html_url":"https://github.com/rocketlaunchr/igo","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocketlaunchr%2Figo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocketlaunchr%2Figo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocketlaunchr%2Figo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocketlaunchr%2Figo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rocketlaunchr","download_url":"https://codeload.github.com/rocketlaunchr/igo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248621336,"owners_count":21134814,"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","golang"],"created_at":"2024-08-01T13:01:32.597Z","updated_at":"2025-04-12T19:32:33.644Z","avatar_url":"https://github.com/rocketlaunchr.png","language":"Go","readme":"# Improved Go (igo) [![GoDoc](http://godoc.org/github.com/rocketlaunchr/igo/stack?status.svg)](https://godoc.org/github.com/rocketlaunchr/igo/stack)\n\n\n\nEveryone knows that Go is a very verbose language. It takes numerous lines of code to do what a few lines of code can do in other languages. This is a deliberate design decision by the Go Authors.\n\nThe igo project provides various syntactical sugar to make your code simpler and easier to read. It works by allowing you to program in `*.igo` files with the fancy new syntax. You then run `igo build` to transpile your `igo` files to standard `go` files which you can then build as per normal.\n\n1. Address Operator (\u0026)\n    - Constants and Functions\n2. Defers for for-loops\n    - `fordefer` guarantees to run prior to the loop's current iteration exiting.\n3. Defer go\n    - Run defer statements in a goroutine\n4. must function\n    - Converts a multi-return value function into a single-return function.\n    - See [#32219](https://github.com/golang/go/issues/32219)\n5. Negative slice indices\n\n**NOTE: igo is pronounced ee-gohr**\n\n⭐ the project to show your appreciation.\n\n## What is included\n\n-   igofmt (auto format code)\n-   igo transpiler (generate standard go code)\n\n## Installation\n\n**Transpiler**\n\n```\ngo get -u github.com/rocketlaunchr/igo\n```\n\nUse `go install` to install the executable.\n\n**Formatter**\n\n```\ngo get -u github.com/rocketlaunchr/igo/igofmt\n```\n\n## Inspiration\n\nMost professional front-end developers are fed up with standard JavaScript. They program using Typescript and then transpile the code to standard ES5 JavaScript. igo adds the same step to the build process.\n\n## Examples\n\n### Address Operator\n\nThe Address Operator allows you to use more visually pleasing syntax. There is no need for a temporary variable. It can be used with `string`, `bool`, `int`, `float64` and function calls where the function returns 1 return value.\n\n```go\n\nfunc main() {\n\n\tmessage := \u0026\"igo is so convenient\"\n\tdisplay(message)\n\n\tdisplay(\u0026`inline string`)\n\n\tdisplay(\u0026defaultMessage())\n\n}\n\nfunc display(m *string) {\n\tif m == nil {\n\t\tfmt.Print(\"no message\")\n\t} else {\n\t\tfmt.Print(*m)\n\t}\n\n}\n\nfunc defaultMessage() string {\n\treturn \"default message\"\n}\n\n```\n\n### Fordefer\n\nSee [Blog post](https://blog.learngoprogramming.com/gotchas-of-defer-in-go-1-8d070894cb01) on why this is an improvement. It can be especially helpful in unit tests.\n\n```go\n\nfor {\n\trow, err := db.Query(\"SELECT ...\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfordefer row.Close()\n}\n\n```\n\n### Defer go\n\nThis feature makes Go's language syntax more internally consistent. There is no reason why `defer` and `go` should not work together.\n\n```go\n\nmux.HandleFunc(\"/\", func(w http.ResponseWriter, req *http.Request) {\n\tstart := time.Now()\n\t// Transmit how long the request took to serve without delaying response to client.\n\tdefer go transmitRequestStats(start)\n\n\tfmt.Fprintf(w, \"Welcome to the home page!\")\n})\n\n```\n\n### Must builtin function\n\n`must` is a \"builtin\" function that converts a multi-return value function (`\"fn\"`) into a single-return value function. `fn's` final return value is expected to be of type `error`. `must` will panic upon `fn` returning an error.\n\nIt is useful in scenarios where you know that no error will actually be returned by `fn` and you just want to use the function inline. Alternatively, you may want to catch the error during local development because no error should be produced in production.\n\n`must` also accepts an optional second argument of type `func(error) error`.\n\nSee [#32219](https://github.com/golang/go/issues/32219)\n\n```go\nimport \"database/sql\"\n\ndb := must(sql.Open(\"mysql\", \"host\"))\n\n```\n\n**LIMITATIONS**\n\n-   Currently, it only works when `fn` returns **two** return values.\n-   It doesn't work when used outside of functions (i.e. initializing package variables).\n-   It works perfectly in simple cases. For more complex cases, peruse the generated code.\n-   A PR would be appreciated by an expert in the `go/types` package. It is possible to create a truly generics-compatible `must` that resolves the limitations above.\n-   Unlike real \"builtin\" functions, `must` is a reserved keyword.\n\n### Negative slice indices\n\nYou can use negative indices to refer to items in a slice starting from the back. It only works with constants and not variables.\n\n```go\nx := []int{0, 1, 2, 3, 4}\n\nx[-3] // x[len(x)-3]\n\nx[-3:-1] // x[len(x)-3:len(x)-1]\n\n```\n\n## How to use\n\n### Transpile\n\n`igo` can accept numerous directories or igo files. The generated go files are saved alongside the igo files.\n\n```\nigo build [igo files...]\n```\n\n### Format Code\n\n`igofmt` will format your code to the standard form. It understands igo syntax.\n\n```\nigofmt [-s] [igo files...]\n```\n\nConfigure your IDE to run `igofmt` upon saving a `*.igo` file.\n`-s` will attempt to simplify the code by running `gofmt -s`.\n\n## Design Decisions and Limitations\n\nPull-Requests are requested for the below deficiencies.\n\n-   For `fordefer`: `goto` statements inside a for-loop that jump outside the for-loop is not implemented. Use `github.com/rocketlaunchr/igo/stack` package manually in such cases.\n-   `goimports` equivalent has not been made.\n-   Address Operator for constants currently only supports `string`, `bool`, `float64` and `int`. The other int types are not supported. This can be fixed by using [go/types](https://github.com/golang/example/tree/master/gotypes) package.\n-   Address Operator feature assumes you have not attempted to redefine `true` and `false` to something/anything else.\n\n## Tips \u0026 Advice\n\n-   Store the `igo` and generated `go` files in your git repository.\n-   Configure your IDE to run `igofmt` upon saving a `*.igo` file.\n\n#\n\n### Legal Information\n\nThe license is a modified MIT license. Refer to the `LICENSE` file for more details.\n\n**© 2018-20 PJ Engineering and Business Solutions Pty. Ltd.**\n\n### Final Notes\n\nFeel free to enhance features by issuing pull-requests.\n","funding_links":[],"categories":["Go Tools","Go","Go 工具","Libraries for creating HTTP middlewares"],"sub_categories":["Routers","代码分析","路由器"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocketlaunchr%2Figo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocketlaunchr%2Figo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocketlaunchr%2Figo/lists"}