forked from luraproject/lura
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
3,896 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
examples/gin/krakend_gin* | ||
examples/mux/krakend_mux* | ||
krakend_gin* | ||
krakend_mux* | ||
server.rsa.crt | ||
server.rsa.key | ||
*.json | ||
*.yml | ||
*.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2016 The KrakenD Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.PHONY: all deps test build run benchmark cover | ||
|
||
all: deps test build | ||
|
||
deps: | ||
go get -u github.com/gin-gonic/gin | ||
go get -u github.com/spf13/viper | ||
go get -u github.com/op/go-logging | ||
|
||
test: | ||
go fmt ./... | ||
go test -cover ./... | ||
go vet ./... | ||
|
||
benchmark: | ||
go test -bench=. -benchtime=3s ./... | ||
|
||
build: build_gin_example build_mux_example | ||
|
||
build_gin_example: | ||
cd examples/gin/ && make && cd ../.. && cp examples/gin/krakend_gin_example* . | ||
|
||
build_mux_example: | ||
cd examples/mux/ && make && cd ../.. && cp examples/mux/krakend_mux_example* . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,111 @@ | ||
## Hey! We are cleaning up and reorganizing our code! | ||
Please Watch or Star this project while we get everything packed for publishing, you'll see the code really soon. | ||
 | ||
|
||
Meanwhile visit the website http://www.krakend.io | ||
# KrakenD [](https://godoc.org/github.com/devopsfaith/krakend) | ||
|
||
# KrakenD | ||
Ultra perfomant API Gateway with middlewares | ||
|
||
## Motivation | ||
|
||
Consumers of REST API content (specially in microservices) often query backend services that weren't coded for the UI implementation. This is of course a good practice, but the UI consumers need to do implementations that suffer a lot of complexity and burden with the sizes of their microservices responses. | ||
|
||
KrakenD is an **API Gateway** builder and proxy generator that sits between the client and all the source servers, adding a new layer that removes all the complexity to the clients, providing them only the information that the UI needs. KrakenD acts as an **aggregator** of many sources into single endpoints and allows you to group, wrap, transform and shrink responses. Additionally it supports a myriad of middelwares and plugins that allow you to extend the functionality, such as adding Oauth authorization or security layers. | ||
|
||
KrakenD not only supports HTTP(S), but because it is a set of generic libraries you can build all type of API Gateways and proxies, including for instance, a RPC gateway. | ||
|
||
### Practical Example | ||
|
||
Fred Calamari is a mobile developer that needs to construct a single front page that requires data from several calls to their backend services, e.g: | ||
|
||
1) api.store.server/products | ||
2) api.store.server/marketing-promos | ||
3) api.users.server/users/{id_user} | ||
4) api.users.server/shopping-cart/{id_user} | ||
|
||
The screen is very simple and _only_ needs to retrieve data from 4 different sources, wait for the round trip and then pick only a few fields of the response. Instead of thing these calls, the mobile could call a single endpoint to KrakenD: | ||
|
||
1) krakend.server/frontpage/{id_user} | ||
|
||
And this is how it would look like: | ||
|
||
 | ||
|
||
The difference in size in this example would be because KrakenD server would have removed unneeded attributes from the responses. | ||
|
||
## What's in this repository? | ||
The source code on which the [KrakenD](http://www.krakend.io) service core is built on. It is designed to work with your own middleware and extend the functionality by using small, independent, reusable components following the Unix philosophy. | ||
|
||
**This repository is only for those who want to build from source a Krakend service** or for those who will reuse any of the components in another application. | ||
|
||
If you just want to use the server, please [download the binary for your architecture](http://www.krakend.io/download). | ||
|
||
|
||
## Library Usage | ||
Krakend is presented as a **go library** that you can include in your own go application to build a powerful proxy or API gateway. In order to get you started several examples of implementations are included in the `examples` folder. | ||
|
||
Of course you will need [go installed](https://golang.org/doc/install) in your system to compile the code. | ||
There is a `Makefile` in every example that will download library dependencies and compile a binary for you to test. Just run: | ||
|
||
$ cd examples/gin | ||
$ make | ||
|
||
Or, if you want to build all the examples, from the root of the project | ||
|
||
$ make | ||
|
||
For the lazy, a ready to use example: | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
|
||
"github.com/devopsfaith/krakend/config/viper" | ||
"github.com/devopsfaith/krakend/logging/gologging" | ||
"github.com/devopsfaith/krakend/proxy" | ||
"github.com/devopsfaith/krakend/router/gin" | ||
) | ||
|
||
func main() { | ||
port := flag.Int("p", 0, "Port of the service") | ||
logLevel := flag.String("l", "ERROR", "Logging level") | ||
debug := flag.Bool("d", false, "Enable the debug") | ||
configFile := flag.String("c", "/etc/krakend/configuration.json", "Path to the configuration filename") | ||
flag.Parse() | ||
|
||
parser := viper.New() | ||
serviceConfig, err := parser.Parse(*configFile) | ||
if err != nil { | ||
log.Fatal("ERROR:", err.Error()) | ||
} | ||
serviceConfig.Debug = serviceConfig.Debug || *debug | ||
if *port != 0 { | ||
serviceConfig.Port = *port | ||
} | ||
|
||
logger := gologging.NewLogger(*logLevel, os.Stdout, "[KRAKEND]") | ||
|
||
routerFactory := gin.DefaultFactory(proxy.DefaultFactory(logger), logger) | ||
|
||
routerFactory.New().Run(serviceConfig) | ||
} | ||
|
||
Visit the [framework overview](/docs/OVERVIEW.md) for more details about the components of the KrakenD. | ||
|
||
### Examples | ||
|
||
1. [gin router](/examples/gin/README.md) | ||
2. [mux router](/examples/mux/README.md) | ||
|
||
## Configuration file | ||
|
||
[KrakenD config file](/docs/CONFIG.md) | ||
|
||
## Benchmarks | ||
|
||
Check out the [benchmark results](/docs/BENCHMARKS.md) of several KrakenD components | ||
|
||
## Contributing | ||
|
||
TBD |
Oops, something went wrong.