├── .vscode ├── settings.json └── configurationCache.log ├── .coveralls.yml ├── example ├── .vscode │ ├── settings.json │ ├── configurationCache.log │ ├── dryrun.log │ └── targets.log ├── README.md ├── conf │ ├── gen_router.data │ └── config.yml ├── gogenerate.go ├── internal │ ├── routers │ │ ├── gen_router.go │ │ └── api_root.go │ ├── service │ │ └── hello │ │ │ └── hello.go │ ├── config │ │ ├── test_def.go │ │ ├── common.go │ │ └── MyIni.go │ ├── core │ │ └── dao.go │ └── api │ │ ├── context.go │ │ └── user.go ├── tools │ └── config.yml ├── docs │ ├── markdown │ │ └── Hello.md │ └── swagger │ │ └── swagger.json ├── go.mod ├── Makefile ├── generate │ └── proto_makefile ├── main.go ├── main_test.go ├── rpc │ └── example │ │ ├── hello.pb.gmsec.go │ │ └── hello.pb.go └── LICENSE ├── .github ├── FUNDING.yml └── workflows │ └── go.yml ├── apidoc ├── README.md ├── rpc │ ├── go.mod │ ├── example │ │ ├── hello.pb.gmsec.go │ │ └── hello.pb.go │ ├── common │ │ └── common_public.pb.go │ └── go.sum └── proto │ ├── common │ └── common_public.proto │ ├── hainlp │ └── hello.proto │ └── example │ └── hello.proto ├── .travis.yml ├── .gitignore ├── Makefile ├── proto_install_mac.sh ├── proto_install_windows_git_bash.sh ├── proto_install_linux.sh ├── proto_source_install.sh ├── README.md └── LICENSE /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "go.inferGopath": false 3 | } -------------------------------------------------------------------------------- /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name:travis-pro 2 | repo_token:0LTKdJPyx19srGcw0Ef8URUlG8fE4K2sa -------------------------------------------------------------------------------- /example/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "makefile.extensionOutputFolder": "./.vscode" 3 | } -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [xxjwxc] 2 | custom: ["https://www.paypal.me/xxjwxc"] 3 | patreon: xxjwxc -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # gmsec服务 2 | 3 | 这是一个示例服务 4 | 5 | 生成 proto 6 | 7 | ``` 8 | go generate 9 | ``` -------------------------------------------------------------------------------- /example/conf/gen_router.data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/gmsec/master/example/conf/gen_router.data -------------------------------------------------------------------------------- /example/gogenerate.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // 编译所有 4 | //go:generate make -s -f generate/proto_makefile 5 | //部分 6 | // go:generate make gen_proto -f generate/proto_makefile 7 | -------------------------------------------------------------------------------- /apidoc/README.md: -------------------------------------------------------------------------------- 1 | # 公共模块 2 | 3 | 此目录主要存放服务接口定义模块 4 | 5 | proto --- 存放proto文件(根据微服务相关相对目录) 6 | rpc --- 存放grpc/gmsec 相关build协议文件 7 | 8 | ----- example 微服务存放路径 9 | ----- Makefile 服务生成文件 10 | -------------------------------------------------------------------------------- /.vscode/configurationCache.log: -------------------------------------------------------------------------------- 1 | {"buildTargets":["clear","install","new","source_install"],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}} -------------------------------------------------------------------------------- /example/.vscode/configurationCache.log: -------------------------------------------------------------------------------- 1 | {"buildTargets":["all","build","clear","gen","install","linux","mac","master","orm","run","source_install","windows"],"launchTargets":[],"customConfigurationProvider":{"workspaceBrowse":{"browsePath":[],"compilerArgs":[]},"fileIndex":[]}} -------------------------------------------------------------------------------- /example/.vscode/dryrun.log: -------------------------------------------------------------------------------- 1 | make.exe --dry-run --always-make --keep-going --print-directory 2 | make.exe: Entering directory 'f:/xxj/work/workspace/github/xxjwxc/gmsec/example' 3 | make clear 4 | make.exe: Leaving directory 'f:/xxj/work/workspace/github/xxjwxc/gmsec/example' 5 | 6 | -------------------------------------------------------------------------------- /example/internal/routers/gen_router.go: -------------------------------------------------------------------------------- 1 | 2 | package routers 3 | 4 | import ( 5 | "github.com/xxjwxc/ginrpc" 6 | ) 7 | 8 | func init() { 9 | ginrpc.SetVersion(1660818462) 10 | ginrpc.AddGenOne("Hello.SayHello", "hello.say_hello", []string{ "post" }) 11 | } 12 | -------------------------------------------------------------------------------- /apidoc/rpc/go.mod: -------------------------------------------------------------------------------- 1 | module rpc 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/gmsec/micro v0.0.0-20210702092856-15091f6bcc57 7 | google.golang.org/grpc v1.36.0 8 | google.golang.org/protobuf v1.25.0 9 | ) 10 | 11 | replace google.golang.org/grpc v1.36.0 => google.golang.org/grpc v1.29.1 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.13.x 4 | - master 5 | 6 | go_import_path: github.com/gmsec/gmsec 7 | 8 | before_install: 9 | - cd example 10 | - go get -t -v ./... 11 | 12 | script: 13 | - go test -race -coverprofile=coverage.txt -covermode=atomic 14 | 15 | after_success: 16 | - bash <(curl -s https://codecov.io/bash) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | /.idea 17 | *.iml -------------------------------------------------------------------------------- /apidoc/proto/common/common_public.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 指定proto版本 2 | 3 | package common; // 指定包名 4 | 5 | // import "google/protobuf/descriptor.proto"; 6 | 7 | // option go_package = "common;common"; // 指定路径 8 | // option go_package = "gmsec/rpc/common"; 9 | option go_package = "rpc/common"; // 指定包路径 10 | 11 | message ResultResp { 12 | bool result = 1; 13 | string msg = 2; 14 | } -------------------------------------------------------------------------------- /apidoc/proto/hainlp/hello.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 指定proto版本 2 | 3 | package hainlp; // 指定包名 4 | import "common/common_public.proto"; 5 | 6 | option go_package = "rpc/hainlp"; // 指定路径 7 | 8 | // 定义HaiNlp服务 9 | service HaiNlp { 10 | // 定义SayHello方法 11 | rpc SayHello(HelloRequest) returns (HelloReply) {} 12 | } 13 | 14 | // HelloRequest 请求结构 15 | message HelloRequest { 16 | string name = 1; // 名字 17 | } 18 | 19 | // HelloReply 响应结构 20 | message HelloReply { 21 | string message = 1; // 消息 22 | common.ResultResp result = 2;// 多proto 文件样例 23 | } 24 | -------------------------------------------------------------------------------- /apidoc/proto/example/hello.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 指定proto版本 2 | 3 | package example; // 指定包名 4 | import "common/common_public.proto"; 5 | 6 | option go_package = "rpc/example"; // 指定路径 7 | 8 | // 定义example服务 9 | service example { 10 | // 定义SayHello方法 11 | rpc SayHello(HelloRequest) returns (HelloReply) {} 12 | } 13 | 14 | // HelloRequest 请求结构 15 | message HelloRequest { 16 | string name = 1; // 名字 17 | } 18 | 19 | // HelloReply 响应结构 20 | message HelloReply { 21 | string message = 1; // 消息 22 | common.ResultResp result = 2;// 多proto 文件样例 23 | } 24 | -------------------------------------------------------------------------------- /example/conf/config.yml: -------------------------------------------------------------------------------- 1 | base: 2 | is_dev : true 3 | serial_number : 1.0.0 4 | service_name : example 5 | service_displayname : exampleserver 6 | sercice_desc : example微服务 7 | mysql_info: 8 | host : localhost 9 | port : 3306 10 | username : root 11 | password : 123456 12 | database : oauth_db 13 | redis_info: 14 | addrs: ["127.0.0.1:6379"] 15 | password: 123456 16 | group_name: oauth2 17 | db: 0 18 | etcd_info: 19 | addrs: ["127.0.0.1:2379"] 20 | timeout: 3 21 | consul_addr: http://192.155.1.150:8500 22 | consul_tag: dev 23 | jaeger_addr: 192.155.1.150:6831 24 | port: 82 25 | -------------------------------------------------------------------------------- /example/internal/service/hello/hello.go: -------------------------------------------------------------------------------- 1 | package hello 2 | 3 | import ( 4 | "context" 5 | proto "example/rpc/example" 6 | "fmt" 7 | 8 | "github.com/xxjwxc/public/tools" 9 | 10 | "google.golang.org/grpc/metadata" 11 | ) 12 | 13 | type Hello struct { 14 | } 15 | 16 | func (h *Hello) SayHello(ctx context.Context, req *proto.HelloRequest) (*proto.HelloReply, error) { 17 | // c := api.WidthContext(ctx) 18 | // tp, _ := c.GetGinCtx().Get("jager_ctx") 19 | // ctx = tp.(context.Context) 20 | md, ok := metadata.FromIncomingContext(ctx) 21 | fmt.Println(md) 22 | fmt.Println(ok) 23 | fmt.Println(req) 24 | return &proto.HelloReply{ 25 | Message: tools.GetRandomString(8), 26 | }, nil 27 | } 28 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | on: [push] 3 | jobs: 4 | 5 | build: 6 | name: Build 7 | runs-on: ubuntu-latest 8 | steps: 9 | 10 | - name: Set up Go 1.13 11 | uses: actions/setup-go@v1 12 | with: 13 | go-version: 1.13 14 | id: go 15 | 16 | - name: Check out code into the Go module directory 17 | uses: actions/checkout@v1 18 | 19 | - name: Get dependencies 20 | run: | 21 | cd ./example 22 | go get -v -t -d ./... 23 | if [ -f Gopkg.toml ]; then 24 | curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh 25 | dep ensure 26 | fi 27 | 28 | - name: Build 29 | run: cd ./example && go build -v . 30 | -------------------------------------------------------------------------------- /example/internal/config/test_def.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "os" 5 | "strings" 6 | ) 7 | 8 | const ( 9 | testFile = ` 10 | serial_number : "1.0" #版本号 11 | service_name : #服务名 12 | service_displayname : #服务显示名 13 | sercice_desc : #服务描述 14 | is_dev : false # 是否开发者模式 15 | out_dir : ./db # 输出目录 16 | singular_table : true # 单表模式:true:禁用表名复数,false:采用表明复数 参考:gorm.SingularTable 17 | simple : true #简单输出 18 | isJsonTag : true #是否打json标记 19 | mysql_info: 20 | host : 127.0.0.1 21 | port : 3306 22 | username : root 23 | password : qwer 24 | database : oauth_db 25 | ` 26 | ) 27 | 28 | // IsRunTesting Determine whether to use it in a test environment.判断是否在测试环境下使用 29 | func IsRunTesting() bool { 30 | if len(os.Args) > 1 { 31 | return strings.HasPrefix(os.Args[1], "-test") 32 | } 33 | return false 34 | } 35 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | service := example 2 | install: 3 | ./proto_install_mac.sh 4 | source_install: 5 | ./proto_install.sh 6 | clear: # 删除proto文件夹下所有go文件(谨慎操作) 7 | rm -rf ./prc/**/*.go 8 | new: #make new service=example 9 | echo start install $(service) 10 | @# 开始替换文件 11 | @test -d $(service) || cp -r ./example/ ./$(service)/ 12 | @find ./$(service)/ -type f -name "*.go" | xargs sed -i 's#example#$(service)#g' -i 13 | @sed -i 's#example#$(service)#g' ./$(service)/go.mod 14 | @sed -i 's#example#$(service)#g' ./$(service)/Makefile 15 | @sed -i 's#example#$(service)#g' ./$(service)/generate/proto_makefile 16 | @sed -i 's#example#$(service)#g' ./$(service)/conf/config.yml 17 | @# 开始更新apidoc 18 | @test -d ./apidoc/proto/$(service)/ || cp -r ./apidoc/proto/example/ ./apidoc/proto/$(service)/ 19 | @sed -i 's#example#$(service)#g' ./apidoc/proto/$(service)/*.proto 20 | @echo service $(service) success -------------------------------------------------------------------------------- /proto_install_mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | version="3.11.4" 4 | 5 | ABROAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${version}/protoc-${version}-osx-x86_64.zip" 6 | INTERNAL_URL="https://github.com.cnpmjs.org/protocolbuffers/protobuf/releases/download/v${version}/protoc-${version}-osx-x86_64.zip" 7 | 8 | # su - xxj -c "qwer" 9 | # download 10 | curl -fLo protobuf.tar.gz ${ABROAD_URL} || curl -fLo protobuf.tar.zip ${INTERNAL_URL} 11 | mkdir protobuf-${version} 12 | tar -xvf protobuf.tar.gz -C ./protobuf-${version} 13 | cd protobuf-${version} 14 | 15 | # install 16 | xattr -c ./bin/protoc # mac 17 | cp -r ./bin/protoc $GOPATH/bin 18 | cd ../ 19 | rm -rf protobuf-${version}/ 20 | rm -rf ./protobuf.tar.gz 21 | 22 | # install go-grpc 23 | go get -u google.golang.org/grpc 24 | go get -u github.com/gmsec/protoc-gen-gmsec 25 | 26 | chmod +x $GOPATH/bin/protoc 27 | 28 | echo "SUCCESS" 29 | #end -------------------------------------------------------------------------------- /proto_install_windows_git_bash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | version="3.11.4" 4 | 5 | ABROAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${version}/protoc-${version}-win64.zip" 6 | INTERNAL_URL="https://github.com.cnpmjs.org/protocolbuffers/protobuf/releases/download/v${version}/protoc-${version}-win64.zip" 7 | 8 | # su - xxj -c "qwer" 9 | # download 10 | curl -fLo protobuf.tar.gz ${ABROAD_URL} || curl -fLo protobuf.tar.zip ${INTERNAL_URL} 11 | mkdir protobuf-${version} 12 | unzip -d ./protobuf-${version}/ protobuf.tar.gz 13 | cd protobuf-${version} 14 | 15 | # install 16 | # xattr -c ./bin/protoc 17 | cp -r ./bin/protoc.exe $GOPATH/bin 18 | cd ../ 19 | rm -rf protobuf-${version}/ 20 | rm -rf ./protobuf.tar.gz 21 | 22 | # install go-grpc 23 | go get -u google.golang.org/grpc 24 | go get -u github.com/gmsec/protoc-gen-gmsec 25 | 26 | # chmod +x $GOPATH/bin/protoc 27 | 28 | echo "SUCCESS" 29 | #end -------------------------------------------------------------------------------- /proto_install_linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | version="3.11.4" 4 | 5 | ABROAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${version}/protoc-${version}-linux-x86_64.zip" 6 | INTERNAL_URL="https://github.com.cnpmjs.org/protocolbuffers/protobuf/releases/download/v${version}/protoc-${version}-linux-x86_64.zip" 7 | 8 | # su - xxj -c "qwer" 9 | # download 10 | curl -fLo protobuf.tar.zip ${ABROAD_URL} || curl -fLo protobuf.tar.zip ${INTERNAL_URL} 11 | mkdir protobuf-${version} 12 | unzip -d ./protobuf-${version} protobuf.tar.zip 13 | cd protobuf-${version} 14 | 15 | # install 16 | # xattr -c ./bin/protoc # mac 17 | cp -r ./bin/protoc $GOPATH/bin 18 | cd ../ 19 | rm -rf protobuf-${version}/ 20 | rm -rf ./protobuf.tar.zip 21 | 22 | # install go-grpc 23 | go get -u google.golang.org/grpc 24 | go get -u github.com/gmsec/protoc-gen-gmsec 25 | 26 | chmod +x $GOPATH/bin/protoc 27 | 28 | echo "SUCCESS" 29 | #end -------------------------------------------------------------------------------- /proto_source_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | version="3.11.4" 4 | 5 | ABROAD_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${version}/protobuf-all-${version}.tar.gz" 6 | INTERNAL_URL="https://github.com.cnpmjs.org/protocolbuffers/protobuf/releases/download/v${version}/protobuf-all-${version}.tar.gz" 7 | 8 | # su - xxj -c "qwer" 9 | # download 10 | curl -fLo protobuf.tar.gz ${ABROAD_URL} || curl -fLo protobuf.tar.zip ${INTERNAL_URL} 11 | tar -xvf protobuf.tar.gz 12 | cd protobuf-${version} 13 | 14 | #build 15 | curPath=$(pwd) 16 | ./configure --prefix=$curPath --enable-shared=no CFLAGS="-fPIC -fvisibility=hidden" CXXFLAGS="-fPIC -fvisibility=hidden" || exit 1 17 | make clean 18 | make -j6 || exit 1 19 | make check 20 | make install 21 | xattr -c ./bin/protoc 22 | cp -r ./bin/protoc $GOPATH/bin 23 | cd ../ 24 | rm -rf protobuf-${version}/ 25 | 26 | # install go-grpc 27 | go get -u google.golang.org/grpc 28 | go get -u github.com/gmsec/protoc-gen-gmsec 29 | 30 | echo "SUCCESS" 31 | #end -------------------------------------------------------------------------------- /example/tools/config.yml: -------------------------------------------------------------------------------- 1 | base: 2 | is_dev : false 3 | out_dir : ./model # 输出目录 4 | url_tag : json # web url tag(json,db(https://github.com/google/go-querystring)) 5 | language : # 语言(English,中 文) 6 | db_tag : gorm # 数据库标签(gorm,db) 7 | simple : true # 简单输出(默认gorm标签不输出) 8 | is_out_sql : false # 是否输出 sql 原信息 9 | is_out_func : true # 是否输出 快捷函数 10 | is_web_tag : true # 是否打web标记(json标记前提条件) 11 | is_web_tag_pk_hidden: true # web标记是否隐藏主键 12 | is_foreign_key : true # 是否导出外键关联 13 | is_gui : false # 是否ui模式显示 14 | is_table_name : true # 是否直接生成表名,列名 15 | is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型 16 | table_prefix : "" # 表前缀, 如果有则使用, 没有留空 17 | db_info: 18 | host : localhost # type=1的时候,host为yml文件全路径 19 | port : 3306 20 | database : oauth_db 21 | username : root 22 | password : 123456 23 | type: 0 # 数据库类型:0:mysql , 1:sqlite , 2:mssql 24 | 25 | # sqlite 26 | # db_info: 27 | # host : /Users/xxj/Downloads/caoguo # type=1的时候,host为yml文件全路径 28 | # port : 29 | # username : 30 | # password : 31 | # database : 32 | # type: 1 # 数据库类型:0:mysql , 1:sqlite , 2:mssql -------------------------------------------------------------------------------- /example/docs/markdown/Hello.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## [推荐查看工具](https://www.iminho.me/) 4 | 5 | ## 总览: 6 | - [Hello] 7 | - [Waiting to write...] 8 | 9 | -------------------- 10 | 11 | ### SayHello 12 | 13 | #### 简要描述: 14 | 15 | - [] 16 | 17 | #### 请求URL: 18 | 19 | - http://localhost:82/example/api/v1/hello.say_hello 20 | 21 | #### 请求方式: 22 | 23 | - post 24 | 25 | #### 请求参数: 26 | 27 | - ` HelloRequest ` : 请求结构 28 | 29 | |参数名|是否必须|类型|说明| 30 | |:---- |:---|:----- |----- | 31 | |`name` | 否|string|名字 | 32 | 33 | 34 | #### 请求示例: 35 | ``` 36 | { 37 | "name": "" 38 | } 39 | ``` 40 | 41 | #### 返回参数说明: 42 | 43 | - ` HelloReply ` : 响应结构 44 | 45 | |参数名|是否必须|类型|说明| 46 | |:---- |:---|:----- |----- | 47 | |`message` | 否|string|消息 | 48 | |`result` | 否|`common.ResultResp`|多proto 文件样例 | 49 | 50 | 51 | #### 返回示例: 52 | 53 | ``` 54 | { 55 | "message": "", 56 | "result": { 57 | "msg": "", 58 | "result": false 59 | } 60 | } 61 | ``` 62 | 63 | #### 备注: 64 | 65 | - 66 | 67 | 68 | -------------------- 69 | -------------------- 70 | 71 | #### 自定义类型: 72 | 73 | #### ` common ` 74 | 75 | 76 | - ` ResultResp ` : 77 | 78 | |参数名|是否必须|类型|说明| 79 | |:---- |:---|:----- |----- | 80 | |`result` | 否|bool| | 81 | |`msg` | 否|string| | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /example/go.mod: -------------------------------------------------------------------------------- 1 | module example 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/chenjiandongx/ginprom v0.0.0-20201217063207-fe11b7f55a35 7 | github.com/gin-gonic/gin v1.9.0 8 | github.com/gmsec/goplugins v0.0.0-20230218035152-908916def79e 9 | github.com/gmsec/micro v0.0.0-20221221102820-e5f69d99428e 10 | github.com/opentracing/opentracing-go v1.2.0 11 | github.com/prometheus/client_golang v1.11.1 12 | github.com/xxjwxc/consult v0.0.0-20211111094307-0c21a44a4cd0 13 | github.com/xxjwxc/ginrpc v0.0.0-20220727093154-897eb26bf971 14 | github.com/xxjwxc/gowp v0.0.0-20200603130651-4d7368b0e285 15 | github.com/xxjwxc/public v0.0.0-20230103091848-ecbc2d279c6a 16 | go.etcd.io/etcd/client/v3 v3.5.0 17 | golang.org/x/crypto v0.6.0 // indirect 18 | golang.org/x/tools v0.6.0 // indirect 19 | google.golang.org/genproto v0.0.0-20230216225411-c8e22ba71e44 // indirect 20 | google.golang.org/grpc v1.53.0 21 | google.golang.org/protobuf v1.28.1 22 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect 23 | gopkg.in/yaml.v3 v3.0.1 24 | rpc v0.0.0-00010101000000-000000000000 25 | 26 | ) 27 | 28 | replace rpc => ../apidoc/rpc/ 29 | 30 | // replace google.golang.org/grpc v1.40.0 => google.golang.org/grpc v1.29.1 31 | 32 | // replace github.com/xxjwxc/public => ../../public 33 | 34 | // replace github.com/xxjwxc/ginrpc => ../../ginrpc 35 | // replace github.com/gmsec/goplugins => ../../goplugins 36 | 37 | // replace github.com/gmsec/micro => ../../micro 38 | -------------------------------------------------------------------------------- /example/internal/core/dao.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "example/internal/config" 5 | "runtime" 6 | 7 | "github.com/xxjwxc/public/errors" 8 | "github.com/xxjwxc/public/mylog" 9 | "github.com/xxjwxc/public/mysqldb" 10 | ) 11 | 12 | // Dao ... 13 | var Dao DaoCore 14 | 15 | // DaoCore core dao 16 | type DaoCore struct { 17 | dbr *mysqldb.MySqlDB // 读库 18 | dbw *mysqldb.MySqlDB // 写库 19 | } 20 | 21 | func init() { 22 | Dao.InitDao() 23 | } 24 | 25 | // GetDB 获取读数据库 26 | func (dao *DaoCore) GetDB() *mysqldb.MySqlDB { 27 | if dao.dbr == nil { 28 | mylog.Error(errors.New("dbr is nil. ")) 29 | } 30 | return dao.dbr 31 | } 32 | 33 | // GetDBr 获取读数据库 34 | func (dao *DaoCore) GetDBr() *mysqldb.MySqlDB { 35 | if dao.dbr == nil { 36 | mylog.Error(errors.New("dbr is nil. ")) 37 | } 38 | return dao.dbr 39 | } 40 | 41 | // GetDBw 获取写数据库 42 | func (dao *DaoCore) GetDBw() *mysqldb.MySqlDB { 43 | if dao.dbw == nil { 44 | mylog.Error(errors.New("dbw is nil. ")) 45 | } 46 | return dao.dbw 47 | } 48 | 49 | // InitDao 初始化dao 50 | func (dao *DaoCore) InitDao() { 51 | runtime.SetFinalizer(dao, dao.Destroy) //析构时触发 52 | 53 | dao.dbr = mysqldb.OnInitDBOrm(config.GetMysqlConStr(), true) 54 | dao.dbw = mysqldb.OnInitDBOrm(config.GetMysqlConStr(), true) 55 | } 56 | 57 | // Destroy 释放 58 | func (dao *DaoCore) Destroy() { 59 | if dao.dbr != nil { 60 | dao.dbr.OnDestoryDB() 61 | } 62 | 63 | if dao.dbw != nil { 64 | dao.dbw.OnDestoryDB() 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /example/Makefile: -------------------------------------------------------------------------------- 1 | NAME := example 2 | all: # 构建 3 | make clear 4 | build: 5 | make clear 6 | ./tools/gormt -o internal/model 7 | go build -o $(NAME) main.go 8 | ./$(NAME) debug 9 | run: 10 | # make clear 11 | # ./tools/gormt -o internal/model 12 | go build -o $(NAME) *.go 13 | ./$(NAME) debug 14 | windows: 15 | CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $(NAME).exe main.go 16 | mac: 17 | CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(NAME) main.go 18 | linux: 19 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(NAME) main.go 20 | clear: 21 | test ! -d internal/model/ || rm -rf internal/model/* 22 | test ! -d err/ || rm -rf err/ 23 | test ! -f $(NAME) || rm $(NAME) 24 | test ! -f $(NAME).exe || rm $(NAME).exe 25 | rm -rf ./prc/$(NAME)/*.go # 删除proto文件夹下所有go文件(谨慎操作) 26 | # gen: 27 | # - mkdir ../rpc 28 | # - mkdir ./rpc/$(+) 29 | # test -L rpc || ln -s ../rpc ./ 30 | # protoc --proto_path="../apidoc/proto/$(SaverName)/" --gmsec_out=plugins=gmsec:./rpc/$(SaverName) hello.proto 31 | gen: 32 | ifeq ($(LANG),) # windows 33 | # test ! -d rpc/ || rm -rf rpc/ 34 | # test -h rpc || ln -s ../rpc ./ 35 | else 36 | # test -h rpc || ln -s ../rpc ./ # with linux/mac 37 | test -d rpc || ln -s ../rpc ./ 38 | endif 39 | go generate 40 | orm: # gormt 生成 orm代码 41 | ./tools/gormt -o internal/model 42 | install: 43 | ../proto_install.sh 44 | source_install: 45 | ../proto_install.sh 46 | master: 47 | go get -u github.com/xxjwxc/public@master 48 | go get -u github.com/xxjwxc/ginrpc@master 49 | go get -u github.com/gmsec/micro@master 50 | go get -u github.com/gmsec/goplugins@master 51 | -------------------------------------------------------------------------------- /example/generate/proto_makefile: -------------------------------------------------------------------------------- 1 | NAME := example 2 | APIDOCDIR := ../apidoc#文档目录 3 | RPCCDIR := $(APIDOCDIR)/rpc#rpc输出目录 4 | 5 | BUILDSHELLFILE :=`ls $(APIDOCDIR)/proto/$(NAME)/*.proto | cut -d'/' -f5` 6 | COMMSHELLFILE :=`ls $(APIDOCDIR)/proto/common/*.proto | cut -d'/' -f5` 7 | 8 | 9 | gen_proto: gen_build gen_base 10 | clean_proto: 11 | rm -f rpc/common/*.pb.go 12 | gen_build:# 自定义注册 13 | @mkdir -p rpc/$(NAME) 14 | @echo "gen_build proto" 15 | @rm -f rpc/$(NAME)/*.pb.go 16 | @rm -f rpc/$(NAME)/*.pb.gmsec.go 17 | @for file in $(BUILDSHELLFILE); do \ 18 | echo build $$file; \ 19 | protoc --proto_path="$(APIDOCDIR)/proto/" --gmsec_out=plugins=gmsec:./ $(NAME)/$$file; \ 20 | done; 21 | @sed -i 's/,omitempty//g' ./rpc/$(NAME)/*.pb.go #开始取消json omitempty 22 | cp -rf ./rpc/$(NAME)/ $(RPCCDIR)/ #子目录向父目录拷贝 23 | #@sed -i 's#common "rpc/common"#common "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.go #开始替换common包 24 | #@sed -i 's#common "rpc/common"#common "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.gmsec.go #开始替换common包 25 | #@sed -i 's#_ "rpc/common"#_ "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.go #开始替换common包 26 | #@sed -i 's#_ "rpc/common"#_ "$(NAME)/rpc/common"#g' ./rpc/$(NAME)/*.pb.gmsec.go #开始替换common包 27 | 28 | gen_base:# 基础库 29 | @mkdir -p $(RPCCDIR)/common 30 | @echo "gen proto" 31 | @rm -f rpc/common/*.pb.go 32 | @rm -f rpc/common/*.pb.gmsec.go 33 | @for file in $(COMMSHELLFILE); do \ 34 | echo base $$file; \ 35 | protoc --proto_path="$(APIDOCDIR)/proto/" --gmsec_out=plugins=gmsec:$(APIDOCDIR)/ common/$$file; \ 36 | done; 37 | @sed -i 's/,omitempty//g' $(RPCCDIR)/common/*.pb.go #开始取消json omitempty 38 | #cp -rf $(RPCCDIR)/common/ ./rpc/ #父目录向当前目录拷贝 39 | 40 | 41 | -------------------------------------------------------------------------------- /example/internal/api/context.go: -------------------------------------------------------------------------------- 1 | // Package api The next version of the underlying category will support automatic parsing of a single struct. 2 | package api 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/gin-gonic/gin" 8 | ginapi "github.com/gmsec/goplugins/api" 9 | "github.com/xxjwxc/public/mylog" 10 | ) 11 | 12 | const ( 13 | //UserToken 用户token 14 | UserToken = "user_token" // 聚合了用户端token user_token 15 | // SessionToken session token 16 | SessionToken = "session_token" 17 | ) 18 | 19 | // Context Wrapping gin context to custom context 20 | type Context struct { // 包装gin的上下文到自定义context 21 | ginapi.Context 22 | } 23 | 24 | // GetUserInfo 获取用户信息 25 | func (c *Context) GetUserInfo() (u *UserInfo, b bool) { 26 | accessToken, err := c.GetGinCtx().Cookie(UserToken) 27 | if err == nil { 28 | return GetUserFromToken(accessToken) 29 | } 30 | 31 | accessToken, err = c.GetGinCtx().Cookie(SessionToken) 32 | if err == nil { 33 | return GetUserFromToken(accessToken) 34 | } 35 | 36 | mylog.ErrorString(err.Error()) // output error string 37 | return nil, false 38 | } 39 | 40 | // GetSessionToken find SessionToken by cookie 41 | func (c *Context) GetSessionToken() string { 42 | sessionToken, _ := c.GetGinCtx().Cookie(SessionToken) 43 | 44 | return sessionToken 45 | } 46 | 47 | // GetClientIP get request ip 48 | func (c *Context) GetClientIP() string { 49 | return c.GetGinCtx().ClientIP() 50 | } 51 | 52 | // NewAPIFunc default of custom handlefunc 53 | func NewAPIFunc(c *gin.Context) interface{} { 54 | return &Context{*ginapi.NewCtx(c)} 55 | } 56 | 57 | // WidthContext 通过ctx获取 58 | func WidthContext(ctx context.Context) *Context { 59 | c := &Context{} 60 | c.Context.Context = ctx 61 | c.WriteHeadToCtx(c.GetGinCtx()) // 默认推送header 到ctx里面 62 | return c 63 | } 64 | -------------------------------------------------------------------------------- /example/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "example/internal/config" 9 | "example/internal/routers" 10 | 11 | "github.com/gin-gonic/gin" 12 | "github.com/gmsec/goplugins/plugin" 13 | "github.com/gmsec/micro" 14 | "github.com/gmsec/micro/registry" 15 | "github.com/gmsec/micro/tracer" 16 | "github.com/xxjwxc/public/mydoc/myswagger" 17 | "github.com/xxjwxc/public/server" 18 | _ "go.etcd.io/etcd/client/v3" 19 | // "github.com/gmsec/micro/tracer" 20 | ) 21 | 22 | // CallBack service call backe 23 | func CallBack() { 24 | // swagger 25 | myswagger.SetHost("https://localhost:" + config.GetPort()) 26 | myswagger.SetBasePath("example") 27 | myswagger.SetSchemes(true, false) 28 | // -----end -- 29 | tracer.WithTracer(config.GetJaeger().Tag, config.GetJaeger().Addr, config.GetJaeger().Percent) // 链路追踪 30 | 31 | reg := registry.NewDNSNamingRegistry() 32 | // reg := etcdv3.NewEtcdv3NamingRegistry(v3.Config{ 33 | // Endpoints: config.GetEtcdInfo().Addrs, 34 | // DialTimeout: time.Second * time.Duration(config.GetEtcdInfo().Timeout), 35 | // }) 36 | // grpc 相关 初始化服务 37 | service := micro.NewService( 38 | micro.WithName("gmsec.srv.example"), 39 | // micro.WithRegisterTTL(time.Second*30), //指定服务注册时间 40 | micro.WithRegisterInterval(time.Second*15), //让服务在指定时间内重新注册 41 | micro.WithRegistryNaming(reg), 42 | ) 43 | // ----------- end 44 | 45 | // gin restful 相关 46 | router := gin.Default() 47 | router.Use(routers.Cors()) 48 | trace := tracer.GetTracer() 49 | if trace != nil { // 链路追踪 50 | router.Use(routers.UseJager(trace)) 51 | } 52 | v1 := router.Group("/example/api/v1") 53 | routers.OnInitRoot(service.Server(), v1) // 自定义初始化 54 | // ------ end 55 | 56 | plg, b := plugin.Run(plugin.WithMicro(service), 57 | plugin.WithGin(router), 58 | plugin.WithAddr(":"+config.GetPort())) 59 | 60 | if b == nil { 61 | plg.Wait() 62 | } 63 | fmt.Println("done") 64 | } 65 | 66 | func main() { 67 | if config.GetIsDev() || len(os.Args) == 0 { 68 | CallBack() 69 | } else { 70 | server.On(config.GetServiceConfig()).Start(CallBack) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /example/internal/api/user.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "encoding/json" 5 | "example/internal/config" 6 | "strconv" 7 | "time" 8 | 9 | "github.com/xxjwxc/public/dev" 10 | "github.com/xxjwxc/public/message" 11 | "github.com/xxjwxc/public/mycache" 12 | 13 | "github.com/xxjwxc/public/myhttp" 14 | ) 15 | 16 | // UserInfo 用户信息 17 | type UserInfo struct { 18 | AccessToken string // token 19 | UserName string // 用户名 20 | ExpireTime int // 超时时间 21 | } 22 | 23 | // MapMessageBody req message body 24 | type MapMessageBody struct { 25 | message.MessageBody 26 | Data map[string]string `json:"data,omitempty"` 27 | } 28 | 29 | // GetUserFromToken 通过token获取用户信息 30 | func GetUserFromToken(token string) (userInfo *UserInfo, b bool) { 31 | if len(token) == 0 { 32 | if dev.IsDev() { 33 | return &UserInfo{ 34 | UserName: "admin", 35 | }, true 36 | } 37 | return 38 | } 39 | 40 | // 先从缓存中获取 41 | if tmp, ok := GetCacheBody(token); ok { 42 | return &UserInfo{ 43 | AccessToken: token, 44 | UserName: tmp.UserName, 45 | ExpireTime: tmp.ExpireTime}, true 46 | } 47 | 48 | parm := make(map[string]string) 49 | parm["token"] = token 50 | bod, _ := json.Marshal(parm) 51 | rBody, _ := myhttp.OnPostJSON(config.GetCheckTokenURL(), string(bod)) 52 | if len(rBody) > 0 { 53 | var msg MapMessageBody 54 | json.Unmarshal([]byte(rBody), &msg) 55 | if msg.State { 56 | SaveCacheBody(token, msg.Data["username"], msg.Data["expire_time"]) // 保存缓存 57 | return &UserInfo{ 58 | AccessToken: token, 59 | UserName: msg.Data["username"], 60 | ExpireTime: strToInt(msg.Data["expire_time"])}, true // 返回结果 61 | } 62 | } 63 | 64 | return 65 | } 66 | 67 | // SaveCacheBody 保存缓存 68 | func SaveCacheBody(accessToken, username, expireTime string) { 69 | tmp := UserInfo{ 70 | AccessToken: accessToken, 71 | UserName: username, 72 | ExpireTime: strToInt(expireTime), 73 | } 74 | // 保存缓存 75 | cache := mycache.NewCache("oauth2") 76 | cache.Add(accessToken, &tmp, time.Duration(tmp.ExpireTime)*time.Second) 77 | //------------------end 78 | } 79 | 80 | // GetCacheBody 获取缓存 81 | func GetCacheBody(token string) (value *UserInfo, b bool) { 82 | value = new(UserInfo) 83 | cache := mycache.NewCache("oauth2") 84 | err := cache.Value(token, &value) 85 | if err != nil { 86 | return nil, false 87 | } 88 | return value, true 89 | } 90 | 91 | func strToInt(src string) int { 92 | i, _ := strconv.Atoi(src) 93 | return i 94 | } 95 | -------------------------------------------------------------------------------- /example/docs/swagger/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "description": "swagger default desc", 5 | "version": "1.0.0", 6 | "title": "Swagger Petstore" 7 | }, 8 | "host": "localhost:82", 9 | "basePath": "/example", 10 | "tags": [ 11 | { 12 | "name": "Hello", 13 | "description": "" 14 | } 15 | ], 16 | "schemes": [ 17 | "http" 18 | ], 19 | "paths": { 20 | "/example/api/v1/hello.say_hello": { 21 | "post": { 22 | "tags": [ 23 | "Hello" 24 | ], 25 | "summary": "", 26 | "description": "", 27 | "consumes": [ 28 | "application/json", 29 | "application/xml" 30 | ], 31 | "produces": [ 32 | "application/json", 33 | "application/xml" 34 | ], 35 | "parameters": [ 36 | { 37 | "in": "body", 38 | "name": "body", 39 | "description": "", 40 | "required": true, 41 | "schema": { 42 | "$ref": "#/definitions/HelloRequest" 43 | } 44 | } 45 | ], 46 | "responses": { 47 | "400": { 48 | "description": "v" 49 | }, 50 | "404": { 51 | "description": "not found" 52 | }, 53 | "405": { 54 | "description": "Validation exception" 55 | } 56 | } 57 | } 58 | } 59 | }, 60 | "securityDefinitions": {}, 61 | "definitions": { 62 | "HelloRequest": { 63 | "type": "object", 64 | "properties": { 65 | "name": { 66 | "type": "string", 67 | "format": "string", 68 | "description": "名字" 69 | } 70 | }, 71 | "xml": { 72 | "name": "", 73 | "wrapped": false 74 | } 75 | } 76 | }, 77 | "externalDocs": { 78 | "description": "Find out more about Swagger", 79 | "url": "https://github.com/xxjwxc/public" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /example/internal/config/common.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "path" 8 | 9 | "github.com/xxjwxc/consult" 10 | "github.com/xxjwxc/consult/consulkv" 11 | "github.com/xxjwxc/public/dev" 12 | "github.com/xxjwxc/public/mylog" 13 | "github.com/xxjwxc/public/tools" 14 | "gopkg.in/yaml.v3" 15 | ) 16 | 17 | // CfgBase base config struct 18 | type CfgBase struct { 19 | SerialNumber string `json:"serial_number" yaml:"serial_number" consul:"serial_number" ` // version.版本号 20 | ServiceName string `json:"service_name" yaml:"service_name" consul:"service_name"` // service name .service名字 21 | ServiceDisplayname string `json:"service_displayname" yaml:"service_displayname" consul:"service_displayname"` // display name .显示名 22 | SerciceDesc string `json:"sercice_desc" yaml:"sercice_desc" consul:"sercice_desc"` // sercice desc .service描述 23 | IsDev bool `json:"is_dev" yaml:"is_dev" consul:"is_dev"` // Is it a development version?是否是开发版本 24 | } 25 | 26 | var _map = Config{} 27 | 28 | var configPath string 29 | 30 | func init() { 31 | configPath = path.Join(tools.GetCurrentDirectory(), "conf/config.yml") 32 | onInit() 33 | dev.OnSetDev(_map.IsDev) 34 | } 35 | 36 | func onInit() { 37 | err := InitFile(configPath) 38 | if err != nil { 39 | fmt.Println("Load config file error: ", err.Error()) 40 | return 41 | } 42 | 43 | // consul 44 | initConsul() 45 | } 46 | 47 | // InitFile default value from file . 48 | func InitFile(filename string) error { 49 | if _, e := os.Stat(filename); e != nil { 50 | fmt.Println("init default config file: ", filename) 51 | if err := SaveToFile(); err == nil { 52 | fmt.Println("done,please restart.") 53 | } else { 54 | fmt.Println("shit,fail", err) 55 | } 56 | os.Exit(0) 57 | } 58 | bs, err := ioutil.ReadFile(filename) 59 | if err != nil { 60 | return err 61 | } 62 | if err := yaml.Unmarshal(bs, &_map); err != nil { 63 | fmt.Println("read config file error: ", err.Error()) 64 | return err 65 | } 66 | return nil 67 | } 68 | 69 | // GetServiceConfig Get service configuration information 70 | func GetServiceConfig() (name, displayName, desc string) { 71 | name = _map.ServiceName 72 | displayName = _map.ServiceDisplayname 73 | desc = _map.SerciceDesc 74 | return 75 | } 76 | 77 | // GetIsDev is is dev 78 | func GetIsDev() bool { 79 | return _map.IsDev 80 | } 81 | 82 | // SetIsDev is is dev 83 | func SetIsDev(b bool) { 84 | _map.IsDev = b 85 | } 86 | 87 | // SaveToFile save config info to file 88 | func SaveToFile() error { 89 | d, err := yaml.Marshal(_map) 90 | if err != nil { 91 | return err 92 | } 93 | tools.WriteFile(configPath, []string{ 94 | string(d), 95 | }, true) 96 | return nil 97 | } 98 | 99 | func initConsul() { 100 | if len(_map.ConsulAddr) > 0 { 101 | // 初始化数据 102 | conf := consulkv.NewConfig( 103 | consulkv.WithPrefix(GetConsulTag()+"/"+_map.ServiceName), // consul kv prefix 104 | consulkv.WithAddress(_map.ConsulAddr), // consul address 105 | ) 106 | if err := conf.Init(); err != nil { 107 | mylog.Error(err) 108 | return 109 | } 110 | consult.AutoLoadConfig(conf, &_map) 111 | 112 | consult.AutoSetConfig(conf, &_map, false) // 执行一次更新 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /example/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "testing" 7 | "time" 8 | 9 | "github.com/xxjwxc/gowp/workpool" 10 | "github.com/xxjwxc/public/dev" 11 | 12 | "context" 13 | 14 | "example/internal/service/hello" 15 | proto "example/rpc/example" 16 | 17 | "github.com/gin-gonic/gin" 18 | "github.com/gmsec/goplugins/api" 19 | "github.com/gmsec/goplugins/plugin" 20 | "github.com/gmsec/micro" 21 | "github.com/xxjwxc/ginrpc" 22 | "github.com/xxjwxc/public/mydoc/myswagger" 23 | ) 24 | 25 | // TestMain test main 26 | func TestServer(m *testing.T) { 27 | // swagger 28 | myswagger.SetHost("https://localhost:8080") 29 | myswagger.SetBasePath("gmsec") 30 | myswagger.SetSchemes(true, false) 31 | // -----end -- 32 | 33 | // reg := registry.NewDNSNamingRegistry() 34 | // reg := etcdv3.NewEtcdv3NamingRegistry(clientv3.Config{ 35 | // Endpoints: []string{"127.0.0.1:2379"}, 36 | // DialTimeout: time.Second * 3, 37 | // }) 38 | 39 | // grpc 相关 初始化服务 40 | service := micro.NewService( 41 | micro.WithName("xxjwxc.lp.srv.eg1"), 42 | micro.WithRegisterTTL(time.Second*30), //指定服务注册时间 43 | // micro.WithRegisterInterval(time.Second*15), //让服务在指定时间内重新注册 44 | // micro.WithRegistryNaming(reg), 45 | ) 46 | h := new(hello.Hello) 47 | proto.RegisterExampleServer(service.Server(), h) // 服务注册 48 | // ----------- end 49 | 50 | // gin restful 相关 51 | base := ginrpc.New(ginrpc.WithCtx(api.NewAPIFunc), ginrpc.WithDebug(dev.IsDev())) 52 | router := gin.Default() 53 | v1 := router.Group("/xxjwxc/api/v1") 54 | base.Register(v1, h) // 对象注册 55 | // ------ end 56 | 57 | plg, _ := plugin.Run(plugin.WithMicro(service), 58 | plugin.WithGin(router), 59 | plugin.WithAddr("localhost:8080")) 60 | defer plg.Stop() 61 | TestClient(m) // client test 62 | plg.Wait() 63 | /*time.Sleep(3 * time.Second) 64 | plg.Stop() 65 | fmt.Println("done")*/ 66 | } 67 | 68 | func TestClient(m *testing.T) { 69 | micro.SetClientServiceName(proto.GetExampleName(), "xxjwxc.lp.srv.eg1") // set client group 70 | // first 71 | // reg := etcdv3.NewEtcdv3NamingRegistry(clientv3.Config{ 72 | // Endpoints: []string{"127.0.0.1:2379"}, 73 | // DialTimeout: time.Second * 3, 74 | // }) 75 | // micro.NewService( 76 | // micro.WithName("xxjwxc2.lp.srv.eg1"), 77 | // // micro.WithRegisterTTL(time.Second*30), //指定服务注册时间 78 | // micro.WithRegisterInterval(time.Second*15), //让服务在指定时间内重新注册 79 | // micro.WithRegistryNaming(reg), 80 | // ) 81 | wp := workpool.New(20) //设置最大线程数 82 | for i := 0; i < 20; i++ { //开启20个请求 83 | wp.Do(func() error { 84 | say := proto.GetExampleClient() 85 | var request proto.HelloRequest 86 | request.Name = fmt.Sprintf("%v", rand.Intn(500)) 87 | 88 | ctx := context.Background() 89 | resp, err := say.SayHello(ctx, &request) 90 | if err != nil { 91 | fmt.Println("==========err:", err) 92 | } 93 | fmt.Println(resp) 94 | return nil 95 | }) 96 | } 97 | wp.Wait() 98 | fmt.Println("=====done") 99 | } 100 | 101 | // func run() { 102 | // say := proto.GetHelloClient() 103 | // var request proto.HelloRequest 104 | // request.Name = fmt.Sprintf("%v", rand.Intn(500)) 105 | 106 | // ctx := context.Background() 107 | // resp, err := say.SayHello(ctx, &request) 108 | // if err != nil { 109 | // fmt.Println("==========err:", err) 110 | // } 111 | // fmt.Println(resp) 112 | // time.Sleep(1 * time.Second) 113 | // } 114 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/gmsec/gmsec.svg?branch=master)](https://travis-ci.org/gmsec/gmsec) 2 | [![Go Report Card](https://goreportcard.com/badge/github.com/gmsec/gmsec)](https://goreportcard.com/report/github.com/gmsec/gmsec) 3 | [![codecov](https://codecov.io/gh/gmsec/gmsec/branch/master/graph/badge.svg)](https://codecov.io/gh/gmsec/gmsec) 4 | [![GoDoc](https://godoc.org/github.com/gmsec/gmsec?status.svg)](https://godoc.org/github.com/gmsec/gmsec) 5 | 6 | 7 | # [gmsec](https://github.com/gmsec/gmsec) 8 | 9 | ### 特点 10 | 11 | - 打通grpc + gin,同时支持grpc 跟 restful 模式 12 | - grpc , gin 公用端口 13 | - gorm 嵌入,自动数据库代码生成 14 | 15 | ### golang 微服务集成框架 16 | 17 | - [grpc](https://github.com/grpc/grpc-go) 18 | - [gorm 自动构建(gormt)](https://github.com/xxjwxc/gormt) 19 | - [gin 参数自动绑定(ginrpc)](https://github.com/xxjwxc/ginrpc) 20 | - [dns 注册发现(mdns)](https://github.com/asim/mdns) 21 | - [markdown/mindoc 文档自动导出](https://github.com/grpc) 22 | - [支持etcd/nacos服务注册于发现](https://github.com/gmsec/goplugins) 23 | 24 | ## 安装 25 | 26 | - install 27 | 28 | - proto环境安装 29 | 30 | ``` 31 | make install 32 | ``` 33 | 34 | - 本地环境搭建(gmsec为例) 35 | 36 | ``` 37 | make gen 38 | ``` 39 | 40 | - 新建一个服务 41 | ``` 42 | make new service=[服务名] 43 | ``` 44 | 45 | ## proto定义 46 | 47 | ``` 48 | syntax = "proto3"; // 指定proto版本 49 | package proto; // 指定包名 50 | option go_package = ".;proto"; // 指定路径 51 | 52 | // 定义Hello服务 53 | service Hello { 54 | // 定义SayHello方法 55 | rpc SayHello(HelloRequest) returns (HelloReply) {} 56 | } 57 | // HelloRequest 请求结构 58 | message HelloRequest { 59 | string name = 1; // 名字 60 | } 61 | // HelloReply 响应结构 62 | message HelloReply { 63 | string message = 1; // 消息 64 | } 65 | ``` 66 | 67 | ## 服务端代码示例 68 | 69 | ``` go 70 | package main 71 | 72 | import ( 73 | "context" 74 | "fmt" 75 | proto "gmsec/rpc/gmsec" 76 | 77 | "github.com/gmsec/goplugins/api" 78 | "github.com/gin-gonic/gin" 79 | "github.com/gmsec/goplugins/plugin" 80 | "github.com/gmsec/micro" 81 | "github.com/xxjwxc/ginrpc" 82 | ) 83 | 84 | func main() { 85 | // grpc 相关 初始化服务 86 | service := micro.NewService( 87 | micro.WithName("lp.srv.eg1"), 88 | ) 89 | h := new(hello) 90 | proto.RegisterHelloServer(service.Server(), h) // 服务注册 91 | // ----------- end 92 | 93 | // gin 相关 94 | base := ginrpc.New(ginrpc.WithCtx(api.NewAPIFunc), ginrpc.WithDebug(dev.IsDev())) 95 | router := gin.Default() 96 | v1 := router.Group("/xxjwxc/api/v1") 97 | base.Register(v1, h) // 对象注册 98 | // ------ end 99 | 100 | plg, _ := plugin.Run(plugin.WithMicro(service),// grpc 入口 101 | plugin.WithGin(router), // http 入口 102 | plugin.WithAddr(":8080")) // 开始服务(公用端口) 103 | 104 | plg.Wait() // 等待结束(ctrl+c) 105 | 106 | fmt.Println("done") 107 | } 108 | 109 | // Ctx gin.Context 到 context.Context 的转换 110 | func Ctx(c *gin.Context) interface{} { 111 | return context.Background() 112 | } 113 | ``` 114 | 115 | ## 客户端代码: 116 | 117 | ``` go 118 | package main 119 | 120 | import ( 121 | "context" 122 | "fmt" 123 | proto "gmsec/rpc/gmsec" 124 | 125 | "github.com/gmsec/micro" 126 | ) 127 | 128 | func main() { 129 | // reg := registry.NewDNSNamingRegistry() 130 | // grpc 相关 注册服务发现等 131 | micro.NewService( 132 | micro.WithName("lp.srv.eg1"), 133 | // micro.WithRegisterTTL(time.Second*30), //指定服务注册时间 134 | // micro.WithRegisterInterval(time.Second*15), //让服务在指定时间内重新注册 135 | // micro.WithRegistryNaming(reg), 136 | ) 137 | // ----------- end 138 | 139 | say := proto.GetHelloClient() 140 | ctx := context.Background() 141 | resp, _ := say.SayHello(ctx, &proto.HelloRequest{Name:"xxjwxc"}) 142 | fmt.Println("result:", resp) 143 | } 144 | ``` 145 | 146 | ## 更多示例 => [传送门](https://github.com/gmsec/gmsec/tree/master/example) 147 | 148 | ## 正在做 149 | - etcdv3 150 | 151 | 152 | ## [传送门](https://github.com/gmsec) 153 | -------------------------------------------------------------------------------- /apidoc/rpc/example/hello.pb.gmsec.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | 3 | package example 4 | 5 | import ( 6 | context "context" 7 | micro "github.com/gmsec/micro" 8 | client "github.com/gmsec/micro/client" 9 | server "github.com/gmsec/micro/server" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | ) 14 | 15 | // Reference imports to suppress errors if they are not otherwise used. 16 | var _ context.Context 17 | var _ grpc.ClientConnInterface 18 | var _ server.Server 19 | var _ client.Client 20 | var _ micro.Service 21 | 22 | // This is a compile-time assertion to ensure that this generated file 23 | // is compatible with the grpc package it is being compiled against. 24 | const _ = grpc.SupportPackageIsVersion6 25 | 26 | // ExampleClient is the client API for Example service. 27 | // 28 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 29 | type ExampleClient interface { 30 | // 定义SayHello方法 31 | SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) 32 | } 33 | 34 | type exampleClient struct { 35 | cc client.Client 36 | } 37 | 38 | // GetExampleName get client name(package.class) 39 | func GetExampleName() string { 40 | return "example.example" 41 | } 42 | 43 | // GetExampleClient get client by clientname 44 | func GetExampleClient() ExampleClient { 45 | cc := micro.GetClient(GetExampleName()) 46 | return &exampleClient{cc} 47 | } 48 | 49 | // GetExampleClientByName get client by custom name 50 | func GetExampleClientByName(name string) ExampleClient { 51 | cc := micro.GetClient(name) 52 | return &exampleClient{cc} 53 | } 54 | 55 | func NewExampleClient(cc client.Client) ExampleClient { 56 | return &exampleClient{cc} 57 | } 58 | 59 | func (c *exampleClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { 60 | conn, err := c.cc.Next() 61 | defer conn.Close() 62 | if err != nil { 63 | return nil, err 64 | } 65 | out := new(HelloReply) 66 | err = conn.Invoke(ctx, "/example.example/SayHello", in, out, opts...) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return out, nil 71 | } 72 | 73 | // ExampleServer is the server API for Example service. 74 | type ExampleServer interface { 75 | // 定义SayHello方法 76 | SayHello(context.Context, *HelloRequest) (*HelloReply, error) 77 | } 78 | 79 | // UnimplementedExampleServer can be embedded to have forward compatible implementations. 80 | type UnimplementedExampleServer struct { 81 | } 82 | 83 | func (*UnimplementedExampleServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { 84 | return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") 85 | } 86 | 87 | func RegisterExampleServer(s server.Server, srv ExampleServer) { 88 | s.GetServer().RegisterService(&_Example_serviceDesc, srv) 89 | } 90 | 91 | func _Example_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 92 | in := new(HelloRequest) 93 | if err := dec(in); err != nil { 94 | return nil, err 95 | } 96 | if interceptor == nil { 97 | return srv.(ExampleServer).SayHello(ctx, in) 98 | } 99 | info := &grpc.UnaryServerInfo{ 100 | Server: srv, 101 | FullMethod: "/example.example/SayHello", 102 | } 103 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 104 | return srv.(ExampleServer).SayHello(ctx, req.(*HelloRequest)) 105 | } 106 | return interceptor(ctx, in, info, handler) 107 | } 108 | 109 | var _Example_serviceDesc = grpc.ServiceDesc{ 110 | ServiceName: "example.example", 111 | HandlerType: (*ExampleServer)(nil), 112 | Methods: []grpc.MethodDesc{ 113 | { 114 | MethodName: "SayHello", 115 | Handler: _Example_SayHello_Handler, 116 | }, 117 | }, 118 | Streams: []grpc.StreamDesc{}, 119 | Metadata: "example/hello.proto", 120 | } 121 | -------------------------------------------------------------------------------- /example/rpc/example/hello.pb.gmsec.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | 3 | package example 4 | 5 | import ( 6 | context "context" 7 | micro "github.com/gmsec/micro" 8 | client "github.com/gmsec/micro/client" 9 | server "github.com/gmsec/micro/server" 10 | grpc "google.golang.org/grpc" 11 | codes "google.golang.org/grpc/codes" 12 | status "google.golang.org/grpc/status" 13 | ) 14 | 15 | // Reference imports to suppress errors if they are not otherwise used. 16 | var _ context.Context 17 | var _ grpc.ClientConnInterface 18 | var _ server.Server 19 | var _ client.Client 20 | var _ micro.Service 21 | 22 | // This is a compile-time assertion to ensure that this generated file 23 | // is compatible with the grpc package it is being compiled against. 24 | const _ = grpc.SupportPackageIsVersion6 25 | 26 | // ExampleClient is the client API for Example service. 27 | // 28 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. 29 | type ExampleClient interface { 30 | // 定义SayHello方法 31 | SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) 32 | } 33 | 34 | type exampleClient struct { 35 | cc client.Client 36 | } 37 | 38 | // GetExampleName get client name(package.class) 39 | func GetExampleName() string { 40 | return "example.example" 41 | } 42 | 43 | // GetExampleClient get client by clientname 44 | func GetExampleClient() ExampleClient { 45 | cc := micro.GetClient(GetExampleName()) 46 | return &exampleClient{cc} 47 | } 48 | 49 | // GetExampleClientByName get client by custom name 50 | func GetExampleClientByName(name string) ExampleClient { 51 | cc := micro.GetClient(name) 52 | return &exampleClient{cc} 53 | } 54 | 55 | func NewExampleClient(cc client.Client) ExampleClient { 56 | return &exampleClient{cc} 57 | } 58 | 59 | func (c *exampleClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) { 60 | conn, err := c.cc.Next() 61 | defer conn.Close() 62 | if err != nil { 63 | return nil, err 64 | } 65 | out := new(HelloReply) 66 | err = conn.Invoke(ctx, "/example.example/SayHello", in, out, opts...) 67 | if err != nil { 68 | return nil, err 69 | } 70 | return out, nil 71 | } 72 | 73 | // ExampleServer is the server API for Example service. 74 | type ExampleServer interface { 75 | // 定义SayHello方法 76 | SayHello(context.Context, *HelloRequest) (*HelloReply, error) 77 | } 78 | 79 | // UnimplementedExampleServer can be embedded to have forward compatible implementations. 80 | type UnimplementedExampleServer struct { 81 | } 82 | 83 | func (*UnimplementedExampleServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { 84 | return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") 85 | } 86 | 87 | func RegisterExampleServer(s server.Server, srv ExampleServer) { 88 | s.GetServer().RegisterService(&_Example_serviceDesc, srv) 89 | } 90 | 91 | func _Example_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 92 | in := new(HelloRequest) 93 | if err := dec(in); err != nil { 94 | return nil, err 95 | } 96 | if interceptor == nil { 97 | return srv.(ExampleServer).SayHello(ctx, in) 98 | } 99 | info := &grpc.UnaryServerInfo{ 100 | Server: srv, 101 | FullMethod: "/example.example/SayHello", 102 | } 103 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 104 | return srv.(ExampleServer).SayHello(ctx, req.(*HelloRequest)) 105 | } 106 | return interceptor(ctx, in, info, handler) 107 | } 108 | 109 | var _Example_serviceDesc = grpc.ServiceDesc{ 110 | ServiceName: "example.example", 111 | HandlerType: (*ExampleServer)(nil), 112 | Methods: []grpc.MethodDesc{ 113 | { 114 | MethodName: "SayHello", 115 | Handler: _Example_SayHello_Handler, 116 | }, 117 | }, 118 | Streams: []grpc.StreamDesc{}, 119 | Metadata: "example/hello.proto", 120 | } 121 | -------------------------------------------------------------------------------- /example/internal/config/MyIni.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // Config custom config struct 8 | type Config struct { 9 | CfgBase `yaml:"base" consul:"base"` 10 | MySQLInfo MysqlDbInfo `yaml:"mysql_info" consul:"mysql_info"` 11 | EtcdInfo EtcdInfo `yaml:"etcd_info" consul:"etcd_info"` 12 | RedisDbInfo RedisDbInfo `yaml:"redis_info" consul:"redis_info"` 13 | Oauth2Url string `yaml:"oauth2_url" consul:"oauth2_url"` 14 | Port string `yaml:"port" consul:"port"` // 端口号 15 | ConsulAddr string `yaml:"consul_addr" consul:"consul_addr" ` // consul 地址 16 | ConsulTag string `yaml:"consul_tag" consul:"consul_tag"` 17 | Jaeger Jaeger `yaml:"jaeger" consul:"jaeger"` 18 | } 19 | 20 | // MysqlDbInfo mysql database information. mysql 数据库信息 21 | type MysqlDbInfo struct { 22 | Host string `validate:"required" consul:"host"` // Host. 地址 23 | Port int `validate:"required" consul:"port"` // Port 端口号 24 | Username string `validate:"required" consul:"username"` // Username 用户名 25 | Password string `yaml:"password" consul:"password"` // Password 密码 26 | Database string `validate:"required" consul:"database"` // Database 数据库名 27 | Type int `consul:"type"` // 数据库类型: 0:mysql , 1:sqlite , 2:mssql 28 | } 29 | 30 | // RedisDbInfo redis database information. redis 数据库信息 31 | type RedisDbInfo struct { 32 | Addrs []string `yaml:"addrs" consul:"addrs"` // Host. 地址 33 | Password string `yaml:"password" consul:"password"` // Password 密码 34 | GroupName string `yaml:"group_name" consul:"group_name"` // 分组名字 35 | DB int `yaml:"db" consul:"db"` // 数据库序号 36 | } 37 | 38 | // EtcdInfo etcd config info 39 | type EtcdInfo struct { 40 | Addrs []string `yaml:"addrs" consul:"addrs"` // Host. 地址 41 | Timeout int `yaml:"timeout" consul:"timeout"` // 超时时间(秒) 42 | } 43 | 44 | // NacosInfo nacos information nacos配置信息 45 | type NacosInfo struct { 46 | IpAddr string `yaml:"ipaddr" consul:"ipaddr"` // 地址 47 | Port uint64 `yaml:"port" consul:"port"` // 端口 48 | Namespace string `yaml:"namespace" consul:"namespace"` // 命名空间 49 | Group string `yaml:"group" consul:"group"` // 组 50 | DataId string `yaml:"dataid" consul:"dataid"` // Key 51 | } 52 | 53 | type Jaeger struct { 54 | Addr string `yaml:"addr" consul:"addr"` // 地址 55 | Percent int `yaml:"password" consul:"percent"` // 比例 56 | Tag string `yaml:"tag" consul:"tag"` // 标记 dev,prd等 57 | } 58 | 59 | // SetMysqlDbInfo Update MySQL configuration information 60 | func SetMysqlDbInfo(info *MysqlDbInfo) { 61 | _map.MySQLInfo = *info 62 | } 63 | 64 | // GetMysqlDbInfo Get MySQL configuration information .获取mysql配置信息 65 | func GetMysqlDbInfo() MysqlDbInfo { 66 | return _map.MySQLInfo 67 | } 68 | 69 | // GetMysqlConStr Get MySQL connection string.获取mysql 连接字符串 70 | func GetMysqlConStr() string { 71 | return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local&interpolateParams=True", 72 | _map.MySQLInfo.Username, 73 | _map.MySQLInfo.Password, 74 | _map.MySQLInfo.Host, 75 | _map.MySQLInfo.Port, 76 | _map.MySQLInfo.Database, 77 | ) 78 | } 79 | 80 | // GetCheckTokenURL checktoken 81 | func GetCheckTokenURL() string { 82 | return _map.Oauth2Url + "/check_token" 83 | } 84 | 85 | // GetLoginURL 登陆用的url 86 | func GetLoginURL() string { 87 | return _map.Oauth2Url + "/authorize" 88 | } 89 | 90 | // GetLoginNoPwdURL token 授权模式登陆 91 | func GetLoginNoPwdURL() string { 92 | return _map.Oauth2Url + "/authorize_nopwd" 93 | } 94 | 95 | // GetPort 获取端口号 96 | func GetPort() string { 97 | return _map.Port 98 | } 99 | 100 | // GetRedisDbInfo Get redis configuration information .获取redis配置信息 101 | func GetRedisDbInfo() RedisDbInfo { 102 | return _map.RedisDbInfo 103 | } 104 | 105 | // GetEtcdInfo get etcd configuration information. 获取etcd 配置信息 106 | func GetEtcdInfo() EtcdInfo { 107 | return _map.EtcdInfo 108 | } 109 | 110 | func GetConsulTag() string { 111 | if len(_map.ConsulTag) > 0 { 112 | return _map.ConsulTag 113 | } 114 | 115 | return "service" 116 | } 117 | 118 | func GetJaeger() Jaeger { 119 | return _map.Jaeger 120 | } 121 | -------------------------------------------------------------------------------- /apidoc/rpc/common/common_public.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.26.0 4 | // protoc v3.11.4 5 | // source: common/common_public.proto 6 | 7 | package common 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type ResultResp struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Result bool `protobuf:"varint,1,opt,name=result,proto3" json:"result"` 29 | Msg string `protobuf:"bytes,2,opt,name=msg,proto3" json:"msg"` 30 | } 31 | 32 | func (x *ResultResp) Reset() { 33 | *x = ResultResp{} 34 | if protoimpl.UnsafeEnabled { 35 | mi := &file_common_common_public_proto_msgTypes[0] 36 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 37 | ms.StoreMessageInfo(mi) 38 | } 39 | } 40 | 41 | func (x *ResultResp) String() string { 42 | return protoimpl.X.MessageStringOf(x) 43 | } 44 | 45 | func (*ResultResp) ProtoMessage() {} 46 | 47 | func (x *ResultResp) ProtoReflect() protoreflect.Message { 48 | mi := &file_common_common_public_proto_msgTypes[0] 49 | if protoimpl.UnsafeEnabled && x != nil { 50 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 51 | if ms.LoadMessageInfo() == nil { 52 | ms.StoreMessageInfo(mi) 53 | } 54 | return ms 55 | } 56 | return mi.MessageOf(x) 57 | } 58 | 59 | // Deprecated: Use ResultResp.ProtoReflect.Descriptor instead. 60 | func (*ResultResp) Descriptor() ([]byte, []int) { 61 | return file_common_common_public_proto_rawDescGZIP(), []int{0} 62 | } 63 | 64 | func (x *ResultResp) GetResult() bool { 65 | if x != nil { 66 | return x.Result 67 | } 68 | return false 69 | } 70 | 71 | func (x *ResultResp) GetMsg() string { 72 | if x != nil { 73 | return x.Msg 74 | } 75 | return "" 76 | } 77 | 78 | var File_common_common_public_proto protoreflect.FileDescriptor 79 | 80 | var file_common_common_public_proto_rawDesc = []byte{ 81 | 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 82 | 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x63, 0x6f, 83 | 0x6d, 0x6d, 0x6f, 0x6e, 0x22, 0x36, 0x0a, 0x0a, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x65, 84 | 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 85 | 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x73, 86 | 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6d, 0x73, 0x67, 0x42, 0x0c, 0x5a, 0x0a, 87 | 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 88 | 0x6f, 0x33, 89 | } 90 | 91 | var ( 92 | file_common_common_public_proto_rawDescOnce sync.Once 93 | file_common_common_public_proto_rawDescData = file_common_common_public_proto_rawDesc 94 | ) 95 | 96 | func file_common_common_public_proto_rawDescGZIP() []byte { 97 | file_common_common_public_proto_rawDescOnce.Do(func() { 98 | file_common_common_public_proto_rawDescData = protoimpl.X.CompressGZIP(file_common_common_public_proto_rawDescData) 99 | }) 100 | return file_common_common_public_proto_rawDescData 101 | } 102 | 103 | var file_common_common_public_proto_msgTypes = make([]protoimpl.MessageInfo, 1) 104 | var file_common_common_public_proto_goTypes = []interface{}{ 105 | (*ResultResp)(nil), // 0: common.ResultResp 106 | } 107 | var file_common_common_public_proto_depIdxs = []int32{ 108 | 0, // [0:0] is the sub-list for method output_type 109 | 0, // [0:0] is the sub-list for method input_type 110 | 0, // [0:0] is the sub-list for extension type_name 111 | 0, // [0:0] is the sub-list for extension extendee 112 | 0, // [0:0] is the sub-list for field type_name 113 | } 114 | 115 | func init() { file_common_common_public_proto_init() } 116 | func file_common_common_public_proto_init() { 117 | if File_common_common_public_proto != nil { 118 | return 119 | } 120 | if !protoimpl.UnsafeEnabled { 121 | file_common_common_public_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 122 | switch v := v.(*ResultResp); i { 123 | case 0: 124 | return &v.state 125 | case 1: 126 | return &v.sizeCache 127 | case 2: 128 | return &v.unknownFields 129 | default: 130 | return nil 131 | } 132 | } 133 | } 134 | type x struct{} 135 | out := protoimpl.TypeBuilder{ 136 | File: protoimpl.DescBuilder{ 137 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 138 | RawDescriptor: file_common_common_public_proto_rawDesc, 139 | NumEnums: 0, 140 | NumMessages: 1, 141 | NumExtensions: 0, 142 | NumServices: 0, 143 | }, 144 | GoTypes: file_common_common_public_proto_goTypes, 145 | DependencyIndexes: file_common_common_public_proto_depIdxs, 146 | MessageInfos: file_common_common_public_proto_msgTypes, 147 | }.Build() 148 | File_common_common_public_proto = out.File 149 | file_common_common_public_proto_rawDesc = nil 150 | file_common_common_public_proto_goTypes = nil 151 | file_common_common_public_proto_depIdxs = nil 152 | } 153 | -------------------------------------------------------------------------------- /example/internal/routers/api_root.go: -------------------------------------------------------------------------------- 1 | package routers 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/http" 7 | "strings" 8 | "time" 9 | 10 | "example/internal/api" 11 | "example/internal/service/hello" 12 | proto "example/rpc/example" 13 | 14 | "github.com/chenjiandongx/ginprom" 15 | "github.com/gin-gonic/gin" 16 | "github.com/gmsec/micro/server" 17 | "github.com/opentracing/opentracing-go" 18 | "github.com/opentracing/opentracing-go/ext" 19 | "github.com/prometheus/client_golang/prometheus/promhttp" 20 | "github.com/xxjwxc/ginrpc" 21 | "github.com/xxjwxc/public/dev" 22 | "github.com/xxjwxc/public/message" 23 | "github.com/xxjwxc/public/mylog" 24 | "github.com/xxjwxc/public/tools" 25 | "google.golang.org/grpc/status" 26 | ) 27 | 28 | // OnInitRoot 初始化 29 | func OnInitRoot(s server.Server, router gin.IRoutes, objs ...interface{}) { 30 | var args []interface{} 31 | h := new(hello.Hello) 32 | args = append(args, h) 33 | proto.RegisterExampleServer(s, h) // 服务注册 34 | args = append(args, objs...) 35 | OnInitRouter(router, args...) 36 | } 37 | 38 | // OnInitRouter 默认初始化 39 | func OnInitRouter(router gin.IRoutes, objs ...interface{}) { 40 | InitFunc(router) 41 | InitObj(router, objs...) 42 | init3rdGrpcHost() 43 | } 44 | 45 | // 初始化第三方host 46 | func init3rdGrpcHost() { 47 | // micro.SetClientServiceName(oauth2.GetOauth2Name(), "gmsec.srv.oauth2") 48 | } 49 | 50 | // InitFunc 默认初始化函数 51 | func InitFunc(router gin.IRoutes) { 52 | router.StaticFS("/file", http.Dir(tools.GetCurrentDirectory()+"/file")) //加载静态资源,一般是上传的资源,例如用户上传的图片 53 | router.GET("/health", func(c *gin.Context) { 54 | c.String(http.StatusOK, "ok") 55 | }) // 健康检查 56 | router.GET("/metrics", ginprom.PromHandler(promhttp.Handler())) // 添加grafana监控 57 | } 58 | 59 | // InitObj 初始化对象 60 | func InitObj(router gin.IRoutes, objs ...interface{}) { 61 | base := ginrpc.New(ginrpc.WithCtx(api.NewAPIFunc), ginrpc.WithOutDoc(dev.IsDev()), ginrpc.WithDebug(dev.IsDev()), 62 | ginrpc.WithOutPath("internal/routers"), ginrpc.WithImportFile("rpc/common", "../apidoc/rpc/common"), 63 | ginrpc.WithBeforeAfter(&JagerGinBeforeAfter{})) 64 | 65 | base.OutDoc(true) 66 | base.Register(router, objs...) // 对象注册 67 | } 68 | 69 | // Cors 跨域问题 70 | func Cors() gin.HandlerFunc { 71 | return func(c *gin.Context) { 72 | method := c.Request.Method 73 | 74 | origin := c.Request.Header.Get("Origin") 75 | var headerKeys []string 76 | for k := range c.Request.Header { 77 | headerKeys = append(headerKeys, k) 78 | } 79 | headerStr := strings.Join(headerKeys, ", ") 80 | if headerStr != "" { 81 | headerStr = fmt.Sprintf("access-control-allow-origin, access-control-allow-headers, %s", headerStr) 82 | } else { 83 | headerStr = "access-control-allow-origin, access-control-allow-headers" 84 | } 85 | if origin != "" { 86 | //下面的都是乱添加的-_-~ 87 | // c.Writer.Header().Set("Access-Control-Allow-Origin", "*") 88 | c.Header("Access-Control-Allow-Origin", "*") 89 | c.Header("Access-Control-Allow-Headers", headerStr) 90 | c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE") 91 | // c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma") 92 | c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type") 93 | // c.Header("Access-Control-Max-Age", "172800") 94 | c.Header("Access-Control-Allow-Credentials", "true") 95 | c.Set("content-type", "application/json") 96 | } 97 | 98 | //放行所有OPTIONS方法 99 | if method == "OPTIONS" { 100 | c.JSON(http.StatusOK, "Options Request!") 101 | } 102 | 103 | c.Next() 104 | } 105 | } 106 | 107 | // UseJager 链路追踪 108 | func UseJager(_tracer opentracing.Tracer) gin.HandlerFunc { 109 | return func(ctx *gin.Context) { 110 | path := ctx.Request.URL.Path 111 | span := _tracer.StartSpan(path, ext.SpanKindRPCServer) 112 | ext.HTTPUrl.Set(span, path) 113 | ext.HTTPMethod.Set(span, ctx.Request.Method) 114 | c := opentracing.ContextWithSpan(ctx, span) 115 | ctx.Set("jager_ctx", c) 116 | ctx.Next() 117 | req, _ := ctx.Get("jager_req") 118 | span.SetTag("request", req) 119 | resp, _ := ctx.Get("jager_resp") 120 | span.SetTag("response", resp) 121 | ext.HTTPStatusCode.Set(span, uint16(ctx.Writer.Status())) 122 | span.Finish() 123 | // tracer.CloseTracer() 124 | } 125 | } 126 | 127 | // JagerGinBeforeAfter 创建一个默认 BeforeAfter Middleware 128 | type JagerGinBeforeAfter struct { 129 | } 130 | 131 | type timeTrace struct{} 132 | 133 | // GinBefore call之前调用 134 | func (d *JagerGinBeforeAfter) GinBefore(req *ginrpc.GinBeforeAfterInfo) bool { 135 | req.Context = context.WithValue(req.Context, timeTrace{}, time.Now()) 136 | req.C.Set("jager_req", tools.JSONDecode(req.Req)) 137 | return true 138 | } 139 | 140 | // GinAfter call之后调用 141 | func (d *JagerGinBeforeAfter) GinAfter(req *ginrpc.GinBeforeAfterInfo) bool { 142 | begin := (req.Context.Value(timeTrace{})).(time.Time) 143 | now := time.Now() 144 | mylog.Info(fmt.Sprintf("[middleware] call[%v] [%v]", req.FuncName, now.Sub(begin))) 145 | 146 | msg := message.GetSuccessMsg() 147 | if req.Error != nil { 148 | msg = message.GetErrorMsg(message.InValidOp) 149 | gerr := status.Convert(req.Error) 150 | if gerr != nil { 151 | msg.Code = int(gerr.Code()) 152 | msg.Error = gerr.Message() 153 | } else { 154 | msg.Error = req.Error.Error() 155 | } 156 | } else { 157 | msg.Data = req.Resp 158 | } 159 | 160 | req.Resp = msg // 设置resp 结果 161 | req.C.Set("jager_resp", tools.JSONDecode(msg)) 162 | 163 | return true 164 | } 165 | -------------------------------------------------------------------------------- /apidoc/rpc/example/hello.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.26.0 4 | // protoc v3.11.4 5 | // source: example/hello.proto 6 | 7 | package example 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | common "rpc/common" 14 | sync "sync" 15 | ) 16 | 17 | const ( 18 | // Verify that this generated code is sufficiently up-to-date. 19 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 20 | // Verify that runtime/protoimpl is sufficiently up-to-date. 21 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 22 | ) 23 | 24 | // HelloRequest 请求结构 25 | type HelloRequest struct { 26 | state protoimpl.MessageState 27 | sizeCache protoimpl.SizeCache 28 | unknownFields protoimpl.UnknownFields 29 | 30 | Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` // 名字 31 | } 32 | 33 | func (x *HelloRequest) Reset() { 34 | *x = HelloRequest{} 35 | if protoimpl.UnsafeEnabled { 36 | mi := &file_example_hello_proto_msgTypes[0] 37 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 38 | ms.StoreMessageInfo(mi) 39 | } 40 | } 41 | 42 | func (x *HelloRequest) String() string { 43 | return protoimpl.X.MessageStringOf(x) 44 | } 45 | 46 | func (*HelloRequest) ProtoMessage() {} 47 | 48 | func (x *HelloRequest) ProtoReflect() protoreflect.Message { 49 | mi := &file_example_hello_proto_msgTypes[0] 50 | if protoimpl.UnsafeEnabled && x != nil { 51 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 52 | if ms.LoadMessageInfo() == nil { 53 | ms.StoreMessageInfo(mi) 54 | } 55 | return ms 56 | } 57 | return mi.MessageOf(x) 58 | } 59 | 60 | // Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. 61 | func (*HelloRequest) Descriptor() ([]byte, []int) { 62 | return file_example_hello_proto_rawDescGZIP(), []int{0} 63 | } 64 | 65 | func (x *HelloRequest) GetName() string { 66 | if x != nil { 67 | return x.Name 68 | } 69 | return "" 70 | } 71 | 72 | // HelloReply 响应结构 73 | type HelloReply struct { 74 | state protoimpl.MessageState 75 | sizeCache protoimpl.SizeCache 76 | unknownFields protoimpl.UnknownFields 77 | 78 | Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message"` // 消息 79 | Result *common.ResultResp `protobuf:"bytes,2,opt,name=result,proto3" json:"result"` // 多proto 文件样例 80 | } 81 | 82 | func (x *HelloReply) Reset() { 83 | *x = HelloReply{} 84 | if protoimpl.UnsafeEnabled { 85 | mi := &file_example_hello_proto_msgTypes[1] 86 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 87 | ms.StoreMessageInfo(mi) 88 | } 89 | } 90 | 91 | func (x *HelloReply) String() string { 92 | return protoimpl.X.MessageStringOf(x) 93 | } 94 | 95 | func (*HelloReply) ProtoMessage() {} 96 | 97 | func (x *HelloReply) ProtoReflect() protoreflect.Message { 98 | mi := &file_example_hello_proto_msgTypes[1] 99 | if protoimpl.UnsafeEnabled && x != nil { 100 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 101 | if ms.LoadMessageInfo() == nil { 102 | ms.StoreMessageInfo(mi) 103 | } 104 | return ms 105 | } 106 | return mi.MessageOf(x) 107 | } 108 | 109 | // Deprecated: Use HelloReply.ProtoReflect.Descriptor instead. 110 | func (*HelloReply) Descriptor() ([]byte, []int) { 111 | return file_example_hello_proto_rawDescGZIP(), []int{1} 112 | } 113 | 114 | func (x *HelloReply) GetMessage() string { 115 | if x != nil { 116 | return x.Message 117 | } 118 | return "" 119 | } 120 | 121 | func (x *HelloReply) GetResult() *common.ResultResp { 122 | if x != nil { 123 | return x.Result 124 | } 125 | return nil 126 | } 127 | 128 | var File_example_hello_proto protoreflect.FileDescriptor 129 | 130 | var file_example_hello_proto_rawDesc = []byte{ 131 | 0x0a, 0x13, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 132 | 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x1a, 0x1a, 133 | 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x70, 0x75, 134 | 0x62, 0x6c, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x22, 0x0a, 0x0c, 0x48, 0x65, 135 | 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 136 | 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x52, 137 | 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 138 | 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 139 | 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x2a, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 140 | 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 141 | 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 142 | 0x6c, 0x74, 0x32, 0x43, 0x0a, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x12, 0x38, 0x0a, 143 | 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x15, 0x2e, 0x65, 0x78, 0x61, 0x6d, 144 | 0x70, 0x6c, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 145 | 0x1a, 0x13, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 146 | 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x0d, 0x5a, 0x0b, 0x72, 0x70, 0x63, 0x2f, 0x65, 147 | 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 148 | } 149 | 150 | var ( 151 | file_example_hello_proto_rawDescOnce sync.Once 152 | file_example_hello_proto_rawDescData = file_example_hello_proto_rawDesc 153 | ) 154 | 155 | func file_example_hello_proto_rawDescGZIP() []byte { 156 | file_example_hello_proto_rawDescOnce.Do(func() { 157 | file_example_hello_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_hello_proto_rawDescData) 158 | }) 159 | return file_example_hello_proto_rawDescData 160 | } 161 | 162 | var file_example_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 163 | var file_example_hello_proto_goTypes = []interface{}{ 164 | (*HelloRequest)(nil), // 0: example.HelloRequest 165 | (*HelloReply)(nil), // 1: example.HelloReply 166 | (*common.ResultResp)(nil), // 2: common.ResultResp 167 | } 168 | var file_example_hello_proto_depIdxs = []int32{ 169 | 2, // 0: example.HelloReply.result:type_name -> common.ResultResp 170 | 0, // 1: example.example.SayHello:input_type -> example.HelloRequest 171 | 1, // 2: example.example.SayHello:output_type -> example.HelloReply 172 | 2, // [2:3] is the sub-list for method output_type 173 | 1, // [1:2] is the sub-list for method input_type 174 | 1, // [1:1] is the sub-list for extension type_name 175 | 1, // [1:1] is the sub-list for extension extendee 176 | 0, // [0:1] is the sub-list for field type_name 177 | } 178 | 179 | func init() { file_example_hello_proto_init() } 180 | func file_example_hello_proto_init() { 181 | if File_example_hello_proto != nil { 182 | return 183 | } 184 | if !protoimpl.UnsafeEnabled { 185 | file_example_hello_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 186 | switch v := v.(*HelloRequest); i { 187 | case 0: 188 | return &v.state 189 | case 1: 190 | return &v.sizeCache 191 | case 2: 192 | return &v.unknownFields 193 | default: 194 | return nil 195 | } 196 | } 197 | file_example_hello_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 198 | switch v := v.(*HelloReply); i { 199 | case 0: 200 | return &v.state 201 | case 1: 202 | return &v.sizeCache 203 | case 2: 204 | return &v.unknownFields 205 | default: 206 | return nil 207 | } 208 | } 209 | } 210 | type x struct{} 211 | out := protoimpl.TypeBuilder{ 212 | File: protoimpl.DescBuilder{ 213 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 214 | RawDescriptor: file_example_hello_proto_rawDesc, 215 | NumEnums: 0, 216 | NumMessages: 2, 217 | NumExtensions: 0, 218 | NumServices: 1, 219 | }, 220 | GoTypes: file_example_hello_proto_goTypes, 221 | DependencyIndexes: file_example_hello_proto_depIdxs, 222 | MessageInfos: file_example_hello_proto_msgTypes, 223 | }.Build() 224 | File_example_hello_proto = out.File 225 | file_example_hello_proto_rawDesc = nil 226 | file_example_hello_proto_goTypes = nil 227 | file_example_hello_proto_depIdxs = nil 228 | } 229 | -------------------------------------------------------------------------------- /example/rpc/example/hello.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.26.0 4 | // protoc v3.11.4 5 | // source: example/hello.proto 6 | 7 | package example 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | common "rpc/common" 14 | sync "sync" 15 | ) 16 | 17 | const ( 18 | // Verify that this generated code is sufficiently up-to-date. 19 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 20 | // Verify that runtime/protoimpl is sufficiently up-to-date. 21 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 22 | ) 23 | 24 | // HelloRequest 请求结构 25 | type HelloRequest struct { 26 | state protoimpl.MessageState 27 | sizeCache protoimpl.SizeCache 28 | unknownFields protoimpl.UnknownFields 29 | 30 | Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"` // 名字 31 | } 32 | 33 | func (x *HelloRequest) Reset() { 34 | *x = HelloRequest{} 35 | if protoimpl.UnsafeEnabled { 36 | mi := &file_example_hello_proto_msgTypes[0] 37 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 38 | ms.StoreMessageInfo(mi) 39 | } 40 | } 41 | 42 | func (x *HelloRequest) String() string { 43 | return protoimpl.X.MessageStringOf(x) 44 | } 45 | 46 | func (*HelloRequest) ProtoMessage() {} 47 | 48 | func (x *HelloRequest) ProtoReflect() protoreflect.Message { 49 | mi := &file_example_hello_proto_msgTypes[0] 50 | if protoimpl.UnsafeEnabled && x != nil { 51 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 52 | if ms.LoadMessageInfo() == nil { 53 | ms.StoreMessageInfo(mi) 54 | } 55 | return ms 56 | } 57 | return mi.MessageOf(x) 58 | } 59 | 60 | // Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead. 61 | func (*HelloRequest) Descriptor() ([]byte, []int) { 62 | return file_example_hello_proto_rawDescGZIP(), []int{0} 63 | } 64 | 65 | func (x *HelloRequest) GetName() string { 66 | if x != nil { 67 | return x.Name 68 | } 69 | return "" 70 | } 71 | 72 | // HelloReply 响应结构 73 | type HelloReply struct { 74 | state protoimpl.MessageState 75 | sizeCache protoimpl.SizeCache 76 | unknownFields protoimpl.UnknownFields 77 | 78 | Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message"` // 消息 79 | Result *common.ResultResp `protobuf:"bytes,2,opt,name=result,proto3" json:"result"` // 多proto 文件样例 80 | } 81 | 82 | func (x *HelloReply) Reset() { 83 | *x = HelloReply{} 84 | if protoimpl.UnsafeEnabled { 85 | mi := &file_example_hello_proto_msgTypes[1] 86 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 87 | ms.StoreMessageInfo(mi) 88 | } 89 | } 90 | 91 | func (x *HelloReply) String() string { 92 | return protoimpl.X.MessageStringOf(x) 93 | } 94 | 95 | func (*HelloReply) ProtoMessage() {} 96 | 97 | func (x *HelloReply) ProtoReflect() protoreflect.Message { 98 | mi := &file_example_hello_proto_msgTypes[1] 99 | if protoimpl.UnsafeEnabled && x != nil { 100 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 101 | if ms.LoadMessageInfo() == nil { 102 | ms.StoreMessageInfo(mi) 103 | } 104 | return ms 105 | } 106 | return mi.MessageOf(x) 107 | } 108 | 109 | // Deprecated: Use HelloReply.ProtoReflect.Descriptor instead. 110 | func (*HelloReply) Descriptor() ([]byte, []int) { 111 | return file_example_hello_proto_rawDescGZIP(), []int{1} 112 | } 113 | 114 | func (x *HelloReply) GetMessage() string { 115 | if x != nil { 116 | return x.Message 117 | } 118 | return "" 119 | } 120 | 121 | func (x *HelloReply) GetResult() *common.ResultResp { 122 | if x != nil { 123 | return x.Result 124 | } 125 | return nil 126 | } 127 | 128 | var File_example_hello_proto protoreflect.FileDescriptor 129 | 130 | var file_example_hello_proto_rawDesc = []byte{ 131 | 0x0a, 0x13, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 132 | 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x1a, 0x1a, 133 | 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x5f, 0x70, 0x75, 134 | 0x62, 0x6c, 0x69, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x22, 0x0a, 0x0c, 0x48, 0x65, 135 | 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 136 | 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x52, 137 | 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 138 | 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 139 | 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x2a, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 140 | 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 141 | 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x65, 0x73, 0x70, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 142 | 0x6c, 0x74, 0x32, 0x43, 0x0a, 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x12, 0x38, 0x0a, 143 | 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x15, 0x2e, 0x65, 0x78, 0x61, 0x6d, 144 | 0x70, 0x6c, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 145 | 0x1a, 0x13, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 146 | 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x0d, 0x5a, 0x0b, 0x72, 0x70, 0x63, 0x2f, 0x65, 147 | 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 148 | } 149 | 150 | var ( 151 | file_example_hello_proto_rawDescOnce sync.Once 152 | file_example_hello_proto_rawDescData = file_example_hello_proto_rawDesc 153 | ) 154 | 155 | func file_example_hello_proto_rawDescGZIP() []byte { 156 | file_example_hello_proto_rawDescOnce.Do(func() { 157 | file_example_hello_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_hello_proto_rawDescData) 158 | }) 159 | return file_example_hello_proto_rawDescData 160 | } 161 | 162 | var file_example_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 163 | var file_example_hello_proto_goTypes = []interface{}{ 164 | (*HelloRequest)(nil), // 0: example.HelloRequest 165 | (*HelloReply)(nil), // 1: example.HelloReply 166 | (*common.ResultResp)(nil), // 2: common.ResultResp 167 | } 168 | var file_example_hello_proto_depIdxs = []int32{ 169 | 2, // 0: example.HelloReply.result:type_name -> common.ResultResp 170 | 0, // 1: example.example.SayHello:input_type -> example.HelloRequest 171 | 1, // 2: example.example.SayHello:output_type -> example.HelloReply 172 | 2, // [2:3] is the sub-list for method output_type 173 | 1, // [1:2] is the sub-list for method input_type 174 | 1, // [1:1] is the sub-list for extension type_name 175 | 1, // [1:1] is the sub-list for extension extendee 176 | 0, // [0:1] is the sub-list for field type_name 177 | } 178 | 179 | func init() { file_example_hello_proto_init() } 180 | func file_example_hello_proto_init() { 181 | if File_example_hello_proto != nil { 182 | return 183 | } 184 | if !protoimpl.UnsafeEnabled { 185 | file_example_hello_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 186 | switch v := v.(*HelloRequest); i { 187 | case 0: 188 | return &v.state 189 | case 1: 190 | return &v.sizeCache 191 | case 2: 192 | return &v.unknownFields 193 | default: 194 | return nil 195 | } 196 | } 197 | file_example_hello_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 198 | switch v := v.(*HelloReply); i { 199 | case 0: 200 | return &v.state 201 | case 1: 202 | return &v.sizeCache 203 | case 2: 204 | return &v.unknownFields 205 | default: 206 | return nil 207 | } 208 | } 209 | } 210 | type x struct{} 211 | out := protoimpl.TypeBuilder{ 212 | File: protoimpl.DescBuilder{ 213 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 214 | RawDescriptor: file_example_hello_proto_rawDesc, 215 | NumEnums: 0, 216 | NumMessages: 2, 217 | NumExtensions: 0, 218 | NumServices: 1, 219 | }, 220 | GoTypes: file_example_hello_proto_goTypes, 221 | DependencyIndexes: file_example_hello_proto_depIdxs, 222 | MessageInfos: file_example_hello_proto_msgTypes, 223 | }.Build() 224 | File_example_hello_proto = out.File 225 | file_example_hello_proto_rawDesc = nil 226 | file_example_hello_proto_goTypes = nil 227 | file_example_hello_proto_depIdxs = nil 228 | } 229 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /example/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /example/.vscode/targets.log: -------------------------------------------------------------------------------- 1 | make.exe all --print-data-base --no-builtin-variables --no-builtin-rules --question 2 | # GNU Make 4.2.1 3 | # Built for x86_64-w64-mingw32 4 | # Copyright (C) 1988-2016 Free Software Foundation, Inc. 5 | # License GPLv3+: GNU GPL version 3 or later 6 | # This is free software: you are free to change and redistribute it. 7 | # There is NO WARRANTY, to the extent permitted by law. 8 | 9 | # Make data base, printed on Fri Aug 19 17:25:12 2022 10 | 11 | # Variables 12 | 13 | # 'override' directive 14 | GNUMAKEFLAGS := 15 | # environment 16 | POWERSHELL_DISTRIBUTION_CHANNEL = MSI:Windows 10 Enterprise 17 | # automatic 18 | ?F = $(notdir $?) 19 | # automatic 20 |