k2let

module
v0.0.0-...-115e584 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2021 License: Apache-2.0

README

k2let项目简介

这是一个自研的项目,基于 go-zero@v1.1.8 的二次开发,它的目标如下:

  • 基于protobuf来生成rpc模板,使用gorm来重构model的代码生成模板。
  • 支持基于dns的resolver,让其能使用k8s service自带的负载均衡和服务发现能力。
  • 去除api模板生成功能,封装apisix的gRPC transcoding功能,作为grpc服务的网关。

主要技术栈和技术难点:

  • service name遵循DNS标签的命名规范[RFC 1123]。

apisix gRPC transcoding

HTTP(s)->APISIX->gRPC server

  1. 往apisix中添加一个Proto:
$ curl http://127.0.0.1:9080/apisix/admin/proto/:proto_id -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "content" : "syntax = \"proto3\";
    package helloworld;
    service Greeter {
        rpc SayHello (HelloRequest) returns (HelloReply) {}
    }
    message HelloRequest {
        string name = 1;
    }
    message HelloReply {
        string message = 1;
    }"
}'
  1. 启动apisix grpc transcoding插件
$ curl http://127.0.0.1:9080/apisix/admin/routes/111 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "methods": ["GET"],
    "uri": "/grpctest",
    "plugins": {
        "grpc-transcode": {
            "proto_id": "1",
            "service": "helloworld.Greeter",
            "method": "SayHello"
        }
    },
    "upstream": {
        "scheme": "grpc",
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:50051": 1
        }
    }
}'
Name Type Requirement Default Valid Description
proto_id string/integer required .proto content id
service string required the grpc service name
method string required the method name of grpc service
deadline number required deadline for grpc,ms
pb_option array[string(pb_option_def)] option protobuf options

支持如下的pb_option_def:

enum as result: 
	enum_as_name,        enum_as_value
int64 as result: 
	int64_as_number,     int64_as_string,   int64_as_hexstring
default values option: 
	auto_default_values, no_default_values, use_default_values, use_default_metatable
hooks option: 
	enable_hooks,        disable_hooks
  1. 测试
$ curl -i http://127.0.0.1:9080/grpctest?name=world
HTTP/1.1 200 OK
Date: Fri, 16 Aug 2019 11:55:36 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server
Proxy-Connection: keep-alive

{"message":"Hello world"}
  1. 关闭apisix grpc transcoding插件
$ curl http://127.0.0.1:9080/apisix/admin/routes/111 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/grpctest",
    "plugins": {},
    "upstream": {
        "scheme": "grpc",
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:50051": 1
        }
    }
}'

Directories

Path Synopsis
core
breaker
多个breaker时,如何处理
多个breaker时,如何处理
executors
处理大块任务的执行 将任务切割为多块来执行
处理大块任务的执行 将任务切割为多块来执行
fs
fx
iox
examples
config
用于从注册中心pull数据,和注册中心push数据到业务服务
用于从注册中心pull数据,和注册中心push数据到业务服务
errors
Package errors provides a way to return detailed information for an RPC request error.
Package errors provides a way to return detailed information for an RPC request error.
logger
Package log provides a log interface
Package log provides a log interface
util/rollwriter
该组件可以与任何可以写入io.Writer的日志包进行配合(包括标准库的log包) 主要特性: 1.
该组件可以与任何可以写入io.Writer的日志包进行配合(包括标准库的log包) 主要特性: 1.
windup/gin-admin/cmd/gin-admin
Package main gin-admin Swagger 文档规则请参考:https://github.com/swaggo/swag#declarative-comments-format 使用方式: go get -u github.com/swaggo/swag/cmd/swag swag init --generalInfo ./cmd/gin-admin/main.go --output ./internal/app/swagger
Package main gin-admin Swagger 文档规则请参考:https://github.com/swaggo/swag#declarative-comments-format 使用方式: go get -u github.com/swaggo/swag/cmd/swag swag init --generalInfo ./cmd/gin-admin/main.go --output ./internal/app/swagger
windup/gin-admin/internal/app/test
Package test 接口测试 使用方式: go test -v
Package test 接口测试 使用方式: go test -v
tpl
util/name
Package name provides methods to verify naming style and format naming style See the method IsNamingValid, FormatFilename
Package name provides methods to verify naming style and format naming style See the method IsNamingValid, FormatFilename
internal/mock
Package mock is a generated protocol buffer package.
Package mock is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL