{"id":13812999,"url":"https://github.com/orange-cloudfoundry/gobis","last_synced_at":"2025-03-17T16:10:21.627Z","repository":{"id":22823622,"uuid":"97407629","full_name":"orange-cloudfoundry/gobis","owner":"orange-cloudfoundry","description":"Gobis is an API Gateway written in go which can be used programmatically or as a standalone server.","archived":false,"fork":false,"pushed_at":"2024-12-30T03:38:36.000Z","size":1280,"stargazers_count":51,"open_issues_count":0,"forks_count":4,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-08T13:29:06.762Z","etag":null,"topics":["api-gateway","go","golang","middleware"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orange-cloudfoundry.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":"2017-07-16T19:57:36.000Z","updated_at":"2024-12-30T03:38:28.000Z","dependencies_parsed_at":"2024-04-19T14:01:24.076Z","dependency_job_id":"4c5cb470-50fb-4c08-a8e0-92480b3f59b6","html_url":"https://github.com/orange-cloudfoundry/gobis","commit_stats":null,"previous_names":[],"tags_count":77,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orange-cloudfoundry%2Fgobis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orange-cloudfoundry%2Fgobis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orange-cloudfoundry%2Fgobis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orange-cloudfoundry%2Fgobis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orange-cloudfoundry","download_url":"https://codeload.github.com/orange-cloudfoundry/gobis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244066180,"owners_count":20392406,"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-gateway","go","golang","middleware"],"created_at":"2024-08-04T04:00:59.571Z","updated_at":"2025-03-17T16:10:21.601Z","avatar_url":"https://github.com/orange-cloudfoundry.png","language":"Go","readme":"# Gobis [![Build Status](https://travis-ci.org/orange-cloudfoundry/gobis.svg?branch=master)](https://travis-ci.org/orange-cloudfoundry/gobis) [![GoDoc](https://godoc.org/github.com/orange-cloudfoundry/gobis?status.svg)](https://godoc.org/github.com/orange-cloudfoundry/gobis)\n\nGobis is a lightweight API Gateway written in go which can be used programmatically or as a standalone server.\n\nIt's largely inspired by [Netflix/zuul](https://github.com/Netflix/zuul).\n\n## Summary\n\n\u003c!-- TOC --\u003e\n* [Gobis ![Build Status](https://travis-ci.org/orange-cloudfoundry/gobis.svg?branch=master) ![GoDoc](https://godoc.org/github.com/orange-cloudfoundry/gobis?status.svg)](#gobis--)\n  * [Summary](#summary)\n  * [Installation](#installation)\n  * [Usage](#usage)\n    * [Headers sent by gobis to reversed app](#headers-sent-by-gobis-to-reversed-app)\n    * [Example using gobis as a middleware](#example-using-gobis-as-a-middleware)\n  * [Middlewares](#middlewares)\n    * [Create your middleware](#create-your-middleware)\n  * [Available middlewares](#available-middlewares)\n  * [Running a standalone server](#running-a-standalone-server)\n  * [Pro tips](#pro-tips)\n  * [FAQ](#faq)\n    * [Why this name ?](#why-this-name-)\n\u003c!-- TOC --\u003e\n\n## Installation\n\n```shell\ngo get github/orange-cloudfoundry/gobis\n```\n\n## Usage\n\nGobis provide an handler to make it useable on your server.\n\nYou can found found `gobis.ProxyRoute` options in the godoc: https://godoc.org/github.com/orange-cloudfoundry/gobis#ProxyRoute\n\n**Example**:\n\n```go\npackage main\nimport (\n        \"github.com/orange-cloudfoundry/gobis\"\n        \"github.com/orange-cloudfoundry/gobis-middlewares/cors\"\n        log \"github.com/sirupsen/logrus\"\n        \"net/http\"\n)\nfunc main(){\n\tbuilder := gobis.Builder()\n\troutes := builder.AddRoute(\"/app/**\", \"http://www.mocky.io/v2/595625d22900008702cd71e8\").\n\t\tWithName(\"myapi\").\n        WithMiddlewareParams(cors.CorsConfig{\n            Cors: \u0026cors.CorsOptions{\n                AllowedOrigins: []string{\"http://localhost\"},\n            },\n        }).\n        Build()\n        \n    log.SetLevel(log.DebugLevel) // set verbosity to debug for logs\n    gobisHandler, err := gobis.NewHandler(routes, cors.NewCors()) // we add cors middleware\n    if err != nil {\n            panic(err)\n    }\n    err = http.ListenAndServe(\":8080\", gobisHandler)\n    if err != nil {\n            panic(err)\n    }\n}\n```\n\nThe builder is a more convenient way to build complex and multiple route programmatically see doc [Builder](https://godoc.org/github.com/orange-cloudfoundry/gobis#Builder).\n\nYou can see doc [DefaultHandlerConfig](https://godoc.org/github.com/orange-cloudfoundry/gobis#DefaultHandlerConfig) to know more about possible parameters.\n\nYou can also see doc [ProxyRoute](https://godoc.org/github.com/orange-cloudfoundry/gobis#ProxyRoute) to see available options for routes.\n\n### Headers sent by gobis to reversed app\n\nGobis will send some headers to the app when the request is forwarded:\n\n- **X-Gobis-Forward**: This is a dummy header to say to the app that the requested was forwarded by gobis.\n- **X-Gobis-Username**: User name of a logged user set by a middleware.\n- **X-Gobis-Groups**: User's groups of a logged user set by a middleware.\n\n### Example using gobis as a middleware\n\n```go\npackage main\nimport (\n\n\"github.com/gorilla/mux\"\n\"github.com/orange-cloudfoundry/gobis\"\n\"github.com/orange-cloudfoundry/gobis-middlewares/cors\"\n\"net/http\"\n)\nfunc main() {\n\trtr := mux.NewRouter()\n\trtr.HandleFunc(\"/hello\", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {\n    \t\tw.Write([]byte(\"hello world\"))\n    }))\n\tbuilder := gobis.Builder()\n    routes := builder.AddRoute(\"/app/**\", \"http://www.mocky.io/v2/595625d22900008702cd71e8\").\n        WithName(\"myapi\").\n        WithMiddlewareParams(cors.CorsConfig{\n            Cors: \u0026cors.CorsOptions{\n                AllowedOrigins: []string{\"http://localhost\"},\n            },\n        }).\n        Build()\n        \n\tmid, err := gobis.NewGobisMiddleware(routes)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t\n\terr = http.ListenAndServe(\":8080\", mid(rtr))\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// hitting /hello will show hello world\n\t// hitting /app/something will forward against gobis\n}\n```\n\n## Middlewares\n\nGobis permit to add middlewares on handler to be able to enhance your upstream url, for example:\n- add basic auth security\n- add monitoring\n- add cors headers\n- ...\n\n### Create your middleware\n\nYou can see example from [cors middleware](https://github.com/orange-cloudfoundry/gobis-middlewares/blob/master/cors.go).\n\nTo use it simply add it to your `RouterFactory`.\n\nHere an example\n\n```go\npackage main\nimport (\n        \"github.com/orange-cloudfoundry/gobis\"\n        log \"github.com/sirupsen/logrus\"\n        \"net/http\"\n)\ntype TraceConfig struct{\n      EnableTrace bool  `mapstructure:\"enable_trace\" json:\"enable_trace\" yaml:\"enable_trace\"`\n}\ntype traceMiddleware struct {}\nfunc (traceMiddleware) Handler(proxyRoute gobis.ProxyRoute, params interface{}, next http.Handler) (http.Handler, error) {\n        // Params has been decode route middleware params, this decoded agains schema you gave in schema function\n        traceConfig := params.(TraceConfig)\n        if !traceConfig.EnableTrace {\n            return next, nil\n        }\n        return TraceHandler(next), nil\n}\n// Schema function is required in order to gobis to decode params from route and sent it back to handler function through `params`\n// It use https://github.com/mitchellh/mapstructure when decode to inject in handler\nfunc (traceMiddleware) Schema() interface{} {\n        return TraceConfig{}\n}\nfunc TraceHandler(h http.Handler) http.Handler {\n        return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n                groups := gobis.Groups(r) // retrieve current user groups set by other middlewares with gobis.AddGroups(r, \"mygroup1\", \"mygroup2\")\n                user := gobis.Username(r) // retrieve current user name set by other middlewares with gobis.SetUsername(r, \"username\")\n                path := gobis.Path(r) // retrieve the path which will be passed to upstream (wihtout trailling path name on your route)\n                routeName := gobis.RouteName(r) // retrieve the current route name which use this handler\n                log.Info(\"Url received: \"+ r.URL.String())\n                h.ServeHTTP(w, r)\n        })\n}\nfunc main(){\n        configHandler := gobis.DefaultHandlerConfig{\n                StartPath: \"/gobis\",\n                Routes: []gobis.ProxyRoute{\n                    {\n                        Name: \"myapi\",\n                        Path: \"/app/**\",\n                        Url: \"http://www.mocky.io/v2/595625d22900008702cd71e8\",\n                    },\n                },\n        }\n        log.SetLevel(log.DebugLevel) // set verbosity to debug for logs\n        gobisHandler, err := gobis.NewDefaultHandler(\n                    configHandler,\n                    \u0026traceMiddleware{},\n                )\n        if err != nil {\n                panic(err)\n        }\n        err = http.ListenAndServe(\":8080\", gobisHandler)\n        if err != nil {\n                panic(err)\n        }\n}\n```\n\n## Available middlewares\n\nMiddlewares are located on repo https://github.com/orange-cloudfoundry/gobis-middlewares\n\n## Running a standalone server\n\nYou can run a prepared gobis server with all default middlewares in one command line, see repo https://github.com/orange-cloudfoundry/gobis-server .\n\nThis server can be ran on cloud like Kubernetes, Cloud Foundry or Heroku.\n\n## Pro tips\n\nYou can set multiple middleware params programmatically by using a dummy structure containing each config you wanna set, example:\n\n```go\npackage main\n\nimport (\n  \"github.com/orange-cloudfoundry/gobis\"\n  \"github.com/orange-cloudfoundry/gobis-middlewares/cors\"\n  \"github.com/orange-cloudfoundry/gobis-middlewares/trace\"\n)\n\nfunc main() {\n  configHandler := gobis.DefaultHandlerConfig{\n    Routes: []gobis.ProxyRoute{\n      {\n        Name: \"myapi\",\n        Path: \"/app/**\",\n        Url:  \"http://www.mocky.io/v2/595625d22900008702cd71e8\",\n        MiddlewareParams: struct {\n          trace.TraceConfig\n          cors.CorsConfig\n        }{\n          TraceConfig: trace.TraceConfig{\n            Trace: \u0026trace.TraceOptions{\n              Enabled: true,\n            },\n          },\n          CorsConfig: cors.CorsConfig{\n            Cors: \u0026cors.CorsOptions{\n              Enabled: true,\n            },\n          },\n        },\n      },\n    },\n  }\n  gobisHandler, err := gobis.NewDefaultHandler(configHandler, trace.NewTrace(), cors.NewCors())\n}\n```\n\n## FAQ\n\n### Why this name ?\n\nGobis is inspired by [zuul](https://github.com/Netflix/zuul) which also a kind of [dinosaur](https://www.wikiwand.com/en/Zuul) \nwhich come from the family of [Ankylosauridae](https://www.wikiwand.com/en/Ankylosauridae), the [gobis(aurus)](https://www.wikiwand.com/en/Gobisaurus) come also from this family.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forange-cloudfoundry%2Fgobis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forange-cloudfoundry%2Fgobis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forange-cloudfoundry%2Fgobis/lists"}