{"id":21296886,"url":"https://github.com/reddec/liana","last_synced_at":"2025-03-15T17:27:29.124Z","repository":{"id":81702528,"uuid":"153110444","full_name":"reddec/liana","owner":"reddec","description":"Tool to generate HTTP wrapper as golang code","archived":false,"fork":false,"pushed_at":"2019-06-05T15:01:58.000Z","size":281,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-09T00:06:39.161Z","etag":null,"topics":["api","code-generator","golang","http"],"latest_commit_sha":null,"homepage":null,"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/reddec.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":"2018-10-15T12:39:25.000Z","updated_at":"2019-06-05T15:02:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d4b2957-feae-4113-aed1-a1713ce544fd","html_url":"https://github.com/reddec/liana","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/reddec%2Fliana","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fliana/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fliana/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reddec%2Fliana/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reddec","download_url":"https://codeload.github.com/reddec/liana/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243764972,"owners_count":20344509,"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":["api","code-generator","golang","http"],"created_at":"2024-11-21T14:30:23.133Z","updated_at":"2025-03-15T17:27:29.091Z","avatar_url":"https://github.com/reddec.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Liana\n\nTool to generate HTTP wrapper as golang code. Expose your own/legacy code as HTTP API without changes.\n\nSupports CLI mode and as a library.\n\n## Usage\n\n* Install from releases page or by\n\n`go get -u -v github.com/reddec/liana/cmd/...`\n\n* Generate wrapper (will put in the same directory as interfaces.go)\n\n`liana path/to/file/with/interfaces.go`\n\n* (optional) add to go generate\n\n```go\n//go:generate liana path/to/file/with/interfaces.go\n```\n\n### CLI\n\n```\nliana [flags] \u003csource file\u003e\n\n  -filter string\n        Name of interface to filter (by default - everything)\n  -get-on-empty\n        Generates GET handlers for methods without input arguments\n  -get-on-simple\n        Generates GET handlers for methods that contains only built-in input arguments\n  -import string\n        Import path (default is no import)\n  -imports string\n        Additional comma separated imports\n  -out string\n        Output file (default same as file plus .http_wrapper.go)\n  -package string\n        Result package name (default same as file)\n  -swagger-dir string\n        Output file for swaggers (if auto - generates to the same dir as out, empty - disabled) (default \"auto\")\n  -swagger-short-names\n        Generates swagger short names for types instead of hashed of package name and type name\n  -swagger-base-path string\n        Swagger base path (default \"/\")\n  -sync\n        Use global lock for each call\n```\n\n\n## Description\n\nEach function in interface that exported and contains no more than one non-error output is exported as POST handle.\n\nHTTP path is presented as kebab-case: for example method `AddTwoPlusThree` will be converted to `/add-two-plus-three`.\n\nFields name are converted to the JSON/XML fields in snake_case: for example method `Calc(hisAmount, Delta int)` will expect\nrequest as JSON/XML object as\n```json\n{ \"his_amount\" : 123, \"delta\" : 1 }\n```\n\n\nHTTP codes range:\n\n* If request contains incorrect data, then `400 Bad Request` error generates\n* If method generates error, then `500 Internal Server Error` error generates\n* If method finished without error (if applicable) and there is no return (void-like method), then `204 No Content` generates\n* If method finished without error (if applicable) and there is return, then `200 OK` generates and contains indented JSON\n\n\nTool generates such methods:\n\n* `func Wrap\u003cinterface name\u003e(handler \u003cinterface name\u003e) http.Handler`,\n* `func GinWrap\u003cinterface name\u003e(handler \u003cinterface name\u003e, router gin.IRoutes) http.Handler`\n\nThe first method just us `gin.Default()` as parameter for the second method and then returns it. Both methods\nregister handlers as described above.\n\n### Example:\n\n\n```go\ntype API interface {\n    Ping()\n    Greet(name string) string\n    TransferTo(user int, amount float64) (string, error)\n}\n\n```\n\nwith implementation\n\n```go\ntype apiImpl struct {}\n\nfunc (a *apiImpl) Ping()             {}\nfunc (a *apiImpl) Greet(name string) { return \"Hello, \"+name }\nfunc (a *apiImpl) TransferTo(user int, amount float64) (string, error) {\n    return \"0xdeadbeaf\", nil\n}\n\n```\n\nuse `liana path/to/file.go`. It will generate by default `path/to/file.http_wrapper.go` that contains\nHTTP handlers for\n\n* POST `/ping` (204 on success)\n* POST `/greet` (200 on success with JSON response).\nRequest example:\n```json\n{\n    \"name\" : \"Reddec\"\n}\n```\n\nResponse example:\n```json\n\"Hello, Reddec!\"\n```\n\n* POST `/transfer-to` (200 on success, 500 on error)\nRequest example:\n```json\n{\n    \"user\" : 123,\n    \"amount\" : 99.21\n}\n```\n\nResponse example:\n```json\n\"0xdeadbeaf\"\n```\n\n\n### Methods\n\nBy default all methods are wrapped by HTTP POST method, however you can change it for next cases:\n\n1. flag `-get-on-empty` allows Liana to generate additional to POST the HTTP GET methods for functions without input arguments.\nFor example:\n\n```golang\ntype Store interface {\n    List() ([]string, error)\n}\n```\n\nwill generate\n\n   * `POST /list`\n   * `GET  /list`\n\n\n2. flag `-get-on-simple` allows Liana to generate additional to POST the HTTP GET methods for functions with only simple (built-in) arguments.\nIn that case, arguments are parsed as HTTP query parameters.\n\nFor example:\n\n```golang\ntype Store interface {\n    List(limit, offset int) ([]string, error)\n}\n```\n\nwill generate\n\n   * `POST /list`\n   * `GET  /list`\n\nand can be tested on localhost by CURl as\n\n    curl \"http://localhost/list?limit=100\u0026offset=0\"\n\n\n\n### Swagger\n\nIf flag `-swagger-dir` is not empty (that's by default) then swagger definition will be generated per each found interface.\n\nOption `-swagger-short-names` allows use in a type names a type names from go without hashed package.\n\nFor example:\n\nType\n\n```golang\npackage sample // in github.com/reddec/liana/sample\n\ntype Item struct {\n    ID int64\n}\n\ntype Store interface {\n    Get() (*Item)\n}\n```\n\nBy default `Item` type will be encoded in swagger as `GithubComReddecLianaSampleItem` and gives a guarantees that type\nname is unique.\n\nWith flag `-swagger-short-names` it will generates just `Item` that much more readable but may generates collision in names.\n\n\nBase url is by default `/` (root) and can be changed by `-swagger-base-path` flag to any value except empty string.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fliana","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freddec%2Fliana","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freddec%2Fliana/lists"}