-
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
8 changed files
with
837 additions
and
0 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 @@ | ||
.DS_Store |
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,5 @@ | ||
# Kratos | ||
|
||
[Iris](https://github.com/kataras/iris) + [Kratos](https://github.com/go-kratos/kratos) integration. | ||
|
||
Example at: [_examples/basic/main.go](_examples/basic/main.go). |
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,64 @@ | ||
module kratos_iris_example | ||
|
||
go 1.19 | ||
|
||
replace github.com/iris-contrib/kratos => ../../ | ||
|
||
require ( | ||
github.com/go-kratos/kratos/v2 v2.5.0 | ||
github.com/iris-contrib/kratos v0.0.0-00010101000000-000000000000 | ||
github.com/kataras/iris/v12 v12.2.0-beta5.0.20220927144459-028ad9f11e16 | ||
) | ||
|
||
require ( | ||
github.com/BurntSushi/toml v1.2.0 // indirect | ||
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect | ||
github.com/CloudyKit/jet/v6 v6.1.0 // indirect | ||
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect | ||
github.com/andybalholm/brotli v1.0.4 // indirect | ||
github.com/aymerick/douceur v0.2.0 // indirect | ||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 // indirect | ||
github.com/fatih/structs v1.1.0 // indirect | ||
github.com/flosch/pongo2/v4 v4.0.2 // indirect | ||
github.com/go-playground/form/v4 v4.2.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/gorilla/css v1.0.0 // indirect | ||
github.com/gorilla/mux v1.8.0 // indirect | ||
github.com/iris-contrib/jade v1.1.4 // indirect | ||
github.com/iris-contrib/schema v0.0.6 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/kataras/blocks v0.0.7 // indirect | ||
github.com/kataras/golog v0.1.7 // indirect | ||
github.com/kataras/pio v0.0.11 // indirect | ||
github.com/kataras/sitemap v0.0.6 // indirect | ||
github.com/kataras/tunnel v0.0.4 // indirect | ||
github.com/klauspost/compress v1.15.11 // indirect | ||
github.com/mailgun/raymond/v2 v2.0.46 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/microcosm-cc/bluemonday v1.0.20 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/schollz/closestmatch v2.1.0+incompatible // indirect | ||
github.com/sirupsen/logrus v1.8.1 // indirect | ||
github.com/tdewolff/minify/v2 v2.12.2 // indirect | ||
github.com/tdewolff/parse/v2 v2.6.3 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect | ||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect | ||
github.com/yosssi/ace v0.0.5 // indirect | ||
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect | ||
golang.org/x/net v0.0.0-20220921203646-d300de134e69 // indirect | ||
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect | ||
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect | ||
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect | ||
google.golang.org/grpc v1.46.2 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,58 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
"github.com/go-kratos/kratos/v2" | ||
"github.com/go-kratos/kratos/v2/errors" | ||
"github.com/go-kratos/kratos/v2/middleware" | ||
"github.com/go-kratos/kratos/v2/middleware/recovery" | ||
"github.com/go-kratos/kratos/v2/transport" | ||
"github.com/go-kratos/kratos/v2/transport/http" | ||
kiris "github.com/iris-contrib/kratos" | ||
"github.com/kataras/iris/v12" | ||
) | ||
|
||
func customMiddleware(handler middleware.Handler) middleware.Handler { | ||
return func(ctx context.Context, req interface{}) (reply interface{}, err error) { | ||
if tr, ok := transport.FromServerContext(ctx); ok { | ||
fmt.Println("operation:", tr.Operation()) | ||
} | ||
reply, err = handler(ctx, req) | ||
return | ||
} | ||
} | ||
|
||
func main() { | ||
router := iris.New() | ||
router.Use(kiris.Middlewares(recovery.Recovery(), customMiddleware)) | ||
router.Get("/helloworld/{name}", func(ctx iris.Context) { | ||
name := ctx.Params().Get("name") | ||
if name == "error" { | ||
kiris.Error(ctx, errors.Unauthorized("auth_error", "no authentication")) | ||
} else { | ||
ctx.JSON(iris.Map{"welcome": name}) | ||
} | ||
}) | ||
|
||
if err := router.Build(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
httpSrv := http.NewServer(http.Address(":8000")) | ||
httpSrv.HandlePrefix("/", router) | ||
|
||
kratosApp := kratos.New( | ||
kratos.Name("iris"), | ||
kratos.Server( | ||
httpSrv, | ||
), | ||
) | ||
|
||
// http://localhost:8000/helloworld/kataras. | ||
if err := kratosApp.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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,60 @@ | ||
module github.com/iris-contrib/kratos | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/go-kratos/kratos/v2 v2.5.0 | ||
github.com/kataras/iris/v12 v12.2.0-beta5.0.20220927144459-028ad9f11e16 | ||
) | ||
|
||
require ( | ||
github.com/BurntSushi/toml v1.2.0 // indirect | ||
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect | ||
github.com/CloudyKit/jet/v6 v6.1.0 // indirect | ||
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect | ||
github.com/andybalholm/brotli v1.0.4 // indirect | ||
github.com/aymerick/douceur v0.2.0 // indirect | ||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 // indirect | ||
github.com/fatih/structs v1.1.0 // indirect | ||
github.com/flosch/pongo2/v4 v4.0.2 // indirect | ||
github.com/go-playground/form/v4 v4.2.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/gorilla/css v1.0.0 // indirect | ||
github.com/gorilla/mux v1.8.0 // indirect | ||
github.com/iris-contrib/jade v1.1.4 // indirect | ||
github.com/iris-contrib/schema v0.0.6 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/kataras/blocks v0.0.7 // indirect | ||
github.com/kataras/golog v0.1.7 // indirect | ||
github.com/kataras/pio v0.0.11 // indirect | ||
github.com/kataras/sitemap v0.0.6 // indirect | ||
github.com/kataras/tunnel v0.0.4 // indirect | ||
github.com/klauspost/compress v1.15.11 // indirect | ||
github.com/mailgun/raymond/v2 v2.0.46 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/microcosm-cc/bluemonday v1.0.20 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/schollz/closestmatch v2.1.0+incompatible // indirect | ||
github.com/sirupsen/logrus v1.8.1 // indirect | ||
github.com/tdewolff/minify/v2 v2.12.2 // indirect | ||
github.com/tdewolff/parse/v2 v2.6.3 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect | ||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect | ||
github.com/yosssi/ace v0.0.5 // indirect | ||
golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect | ||
golang.org/x/net v0.0.0-20220921203646-d300de134e69 // indirect | ||
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect | ||
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect | ||
google.golang.org/grpc v1.46.2 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.