From 45fbb594dcfad9c257fd68b8bde48cf69aa88d7d Mon Sep 17 00:00:00 2001 From: shenqidebaozi Date: Thu, 19 May 2022 22:38:56 +0800 Subject: [PATCH 1/3] feat: add kratos quick start --- docs/quick-start/quick-start-kratos.md | 41 +++++++++++++++++++ .../current/quick-start/quick-start-kratos.md | 36 ++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/docs/quick-start/quick-start-kratos.md b/docs/quick-start/quick-start-kratos.md index 5a84004..03f5982 100644 --- a/docs/quick-start/quick-start-kratos.md +++ b/docs/quick-start/quick-start-kratos.md @@ -5,3 +5,44 @@ sidebar_position: 2 # Use Opensergo with Kratos T.B.D. +--- +sidebar_position: 2 +--- + +# Use Opensergo with Kratos + +## Kratos Overview +[Kratos](github.com/go-kratos/kratos) Kratos is a microservice-oriented governance framework implemented by Golang, which offers convenient capabilities to help you quickly build a bulletproof application from scratch. + +> The name is inspired by the game God of War which is based on Greek myths, tells the adventures of Kratos who became a god of war from a mortal and launched a god-killing slaughter. + +## Access OpenSergo in Kratos + +Kratos design concept is highly customizable. Users can introduce different implementations according to their own needs. Therefore, when we access OpenSergo, we only need to introduce OpenSergo contrib to report the service information to OpenSergo. The code is as follows: +``` +// ... + + app := kratos.New( + kratos.Name(Name), + kratos.Server( + httpSrv, + grpcSrv, + ), + ) + osg, err := opensergo.New(opensergo.WithEndpoint("localhost:9090")) + if err != nil { + return + } + err = osg.ReportMetadata(context.Background(), app) + if err != nil { + return + } + if err := app.Run(); err != nil { + log.Fatal(err) + } +} +``` + +# References +- [Kratos docs](https://go-kratos.dev/docs/) +- [OpenSergo example](https://github.com/go-kratos/examples/tree/main/opensergo) \ No newline at end of file diff --git a/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md b/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md index 128dbfd..74931fe 100644 --- a/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md +++ b/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md @@ -3,3 +3,39 @@ sidebar_position: 2 --- # Kratos 快速接入 OpenSergo + +## Kratos 简介 +[Kratos](github.com/go-kratos/kratos) 是一套轻量级 Go 微服务框架,包含大量微服务相关框架及工具。 + +> 名字来源于:《战神》游戏以希腊神话为背景,讲述奎托斯(Kratos)由凡人成为战神并展开弑神屠杀的冒险经历。 + +## 在 Kratos中接入 OpenSergo + +Kratos 的设计理念就是高度的可定制化,用户可以根据自己的需求引入不同的实现,所以我们接入OpenSergo只需要引入 OpenSergo contrib 即可将服务信息上报到 OpenSergo 中, 代码如下: +``` +// ... + + app := kratos.New( + kratos.Name(Name), + kratos.Server( + httpSrv, + grpcSrv, + ), + ) + osg, err := opensergo.New(opensergo.WithEndpoint("localhost:9090")) + if err != nil { + return + } + err = osg.ReportMetadata(context.Background(), app) + if err != nil { + return + } + if err := app.Run(); err != nil { + log.Fatal(err) + } +} +``` + +# 相关资料 +- [Kratos 文档](https://go-kratos.dev/docs/) +- [OpenSergo 接入示例](https://github.com/go-kratos/examples/tree/main/opensergo) \ No newline at end of file From fb2665b5fa3e0615ee87faea85731fd3cdef0a60 Mon Sep 17 00:00:00 2001 From: shenqidebaozi Date: Thu, 19 May 2022 22:40:53 +0800 Subject: [PATCH 2/3] fix --- docs/quick-start/quick-start-kratos.md | 2 -- .../current/quick-start/quick-start-kratos.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/docs/quick-start/quick-start-kratos.md b/docs/quick-start/quick-start-kratos.md index 03f5982..ab00d64 100644 --- a/docs/quick-start/quick-start-kratos.md +++ b/docs/quick-start/quick-start-kratos.md @@ -21,7 +21,6 @@ sidebar_position: 2 Kratos design concept is highly customizable. Users can introduce different implementations according to their own needs. Therefore, when we access OpenSergo, we only need to introduce OpenSergo contrib to report the service information to OpenSergo. The code is as follows: ``` // ... - app := kratos.New( kratos.Name(Name), kratos.Server( @@ -40,7 +39,6 @@ Kratos design concept is highly customizable. Users can introduce different impl if err := app.Run(); err != nil { log.Fatal(err) } -} ``` # References diff --git a/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md b/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md index 74931fe..21d46b9 100644 --- a/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md +++ b/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md @@ -14,7 +14,6 @@ sidebar_position: 2 Kratos 的设计理念就是高度的可定制化,用户可以根据自己的需求引入不同的实现,所以我们接入OpenSergo只需要引入 OpenSergo contrib 即可将服务信息上报到 OpenSergo 中, 代码如下: ``` // ... - app := kratos.New( kratos.Name(Name), kratos.Server( @@ -33,7 +32,6 @@ Kratos 的设计理念就是高度的可定制化,用户可以根据自己的 if err := app.Run(); err != nil { log.Fatal(err) } -} ``` # 相关资料 From d52d19d64a09c932cb3c4e6c5a1df940a814f923 Mon Sep 17 00:00:00 2001 From: shenqidebaozi Date: Thu, 19 May 2022 22:59:42 +0800 Subject: [PATCH 3/3] clean code --- docs/quick-start/quick-start-kratos.md | 9 ++++----- .../current/quick-start/quick-start-kratos.md | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/quick-start/quick-start-kratos.md b/docs/quick-start/quick-start-kratos.md index ab00d64..e81b5d4 100644 --- a/docs/quick-start/quick-start-kratos.md +++ b/docs/quick-start/quick-start-kratos.md @@ -28,13 +28,12 @@ Kratos design concept is highly customizable. Users can introduce different impl grpcSrv, ), ) - osg, err := opensergo.New(opensergo.WithEndpoint("localhost:9090")) + osg, err := opensergo.New(opensergo.WithEndpoint("locahost:9090")) if err != nil { - return + log.Fatal(err) } - err = osg.ReportMetadata(context.Background(), app) - if err != nil { - return + if err = osg.ReportMetadata(context.Background(), app); err != nil { + log.Fatal(err) } if err := app.Run(); err != nil { log.Fatal(err) diff --git a/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md b/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md index 21d46b9..b4362b5 100644 --- a/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md +++ b/i18n/zh-cn/docusaurus-plugin-content-docs/current/quick-start/quick-start-kratos.md @@ -21,13 +21,12 @@ Kratos 的设计理念就是高度的可定制化,用户可以根据自己的 grpcSrv, ), ) - osg, err := opensergo.New(opensergo.WithEndpoint("localhost:9090")) + osg, err := opensergo.New(opensergo.WithEndpoint("locahost:9090")) if err != nil { - return + log.Fatal(err) } - err = osg.ReportMetadata(context.Background(), app) - if err != nil { - return + if err = osg.ReportMetadata(context.Background(), app); err != nil { + log.Fatal(err) } if err := app.Run(); err != nil { log.Fatal(err)