From 650cd6c294c623ad3a8a2ba7df1c5ddc62f72c69 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Wed, 27 Dec 2017 03:17:06 +0200 Subject: [PATCH] add images for hero basic examples to be easier to understand Former-commit-id: 012ec70fc7761e899f4114f956839a6adce7c21a --- _examples/hero/basic/README.md | 13 +++++++++ _examples/hero/basic/main.go | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 _examples/hero/basic/README.md create mode 100644 _examples/hero/basic/main.go diff --git a/_examples/hero/basic/README.md b/_examples/hero/basic/README.md new file mode 100644 index 00000000..59465659 --- /dev/null +++ b/_examples/hero/basic/README.md @@ -0,0 +1,13 @@ +# hero: basic + +## 1. Path Parameters - Built'n Dependencies + +![](https://github.com/kataras/explore/raw/master/iris/hero/hero-1-monokai.png) + +## 2. Services - Static Dependencies + +![](https://github.com/kataras/explore/raw/master/iris/hero/hero-2-monokai.png) + +## References + +- [explore](https://github.com/kataras/explore) \ No newline at end of file diff --git a/_examples/hero/basic/main.go b/_examples/hero/basic/main.go new file mode 100644 index 00000000..0a4a3491 --- /dev/null +++ b/_examples/hero/basic/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "github.com/kataras/iris" + + "github.com/kataras/iris/hero" +) + +func main() { + + app := iris.New() + + // 1 + helloHandler := hero.Handler(hello) + app.Get("/{to:string}", helloHandler) + + // 2 + hero.Register(&myTestService{ + prefix: "Service: Hello", + }) + + helloServiceHandler := hero.Handler(helloService) + app.Get("/service/{to:string}", helloServiceHandler) + + // http://localhost:8080/your_name + // http://localhost:8080/service/your_name + app.Run(iris.Addr(":8080")) +} + +func hello(to string) string { + return "Hello " + to +} + +type Service interface { + SayHello(to string) string +} + +type myTestService struct { + prefix string +} + +func (s *myTestService) SayHello(to string) string { + return s.prefix + " " + to +} + +func helloService(to string, service Service) string { + return service.SayHello(to) +}