add goa examples

This commit is contained in:
CaptainNEO
2022-03-07 20:49:02 +08:00
commit e2fd9f666e
39 changed files with 3858 additions and 0 deletions

View File

@@ -0,0 +1,363 @@
// Code generated with goa v3.6.0, DO NOT EDIT.
//
// Service1 protocol buffer definition
//
// Command:
// $ goa gen goa_example/design
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.19.4
// source: goadesign_goagen_service1.proto
package service1pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type SigninRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *SigninRequest) Reset() {
*x = SigninRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_goadesign_goagen_service1_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SigninRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SigninRequest) ProtoMessage() {}
func (x *SigninRequest) ProtoReflect() protoreflect.Message {
mi := &file_goadesign_goagen_service1_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SigninRequest.ProtoReflect.Descriptor instead.
func (*SigninRequest) Descriptor() ([]byte, []int) {
return file_goadesign_goagen_service1_proto_rawDescGZIP(), []int{0}
}
type SigninResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// JWT token
Jwt string `protobuf:"bytes,1,opt,name=jwt,proto3" json:"jwt,omitempty"`
// API Key
ApiKey string `protobuf:"bytes,2,opt,name=api_key,json=apiKey,proto3" json:"api_key,omitempty"`
// OAuth2 token
OauthToken string `protobuf:"bytes,3,opt,name=oauth_token,json=oauthToken,proto3" json:"oauth_token,omitempty"`
}
func (x *SigninResponse) Reset() {
*x = SigninResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_goadesign_goagen_service1_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SigninResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SigninResponse) ProtoMessage() {}
func (x *SigninResponse) ProtoReflect() protoreflect.Message {
mi := &file_goadesign_goagen_service1_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SigninResponse.ProtoReflect.Descriptor instead.
func (*SigninResponse) Descriptor() ([]byte, []int) {
return file_goadesign_goagen_service1_proto_rawDescGZIP(), []int{1}
}
func (x *SigninResponse) GetJwt() string {
if x != nil {
return x.Jwt
}
return ""
}
func (x *SigninResponse) GetApiKey() string {
if x != nil {
return x.ApiKey
}
return ""
}
func (x *SigninResponse) GetOauthToken() string {
if x != nil {
return x.OauthToken
}
return ""
}
type SecureRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Whether to force auth failure even with a valid JWT
Fail bool `protobuf:"varint,1,opt,name=fail,proto3" json:"fail,omitempty"`
}
func (x *SecureRequest) Reset() {
*x = SecureRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_goadesign_goagen_service1_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SecureRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SecureRequest) ProtoMessage() {}
func (x *SecureRequest) ProtoReflect() protoreflect.Message {
mi := &file_goadesign_goagen_service1_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SecureRequest.ProtoReflect.Descriptor instead.
func (*SecureRequest) Descriptor() ([]byte, []int) {
return file_goadesign_goagen_service1_proto_rawDescGZIP(), []int{2}
}
func (x *SecureRequest) GetFail() bool {
if x != nil {
return x.Fail
}
return false
}
type SecureResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Field string `protobuf:"bytes,1,opt,name=field,proto3" json:"field,omitempty"`
}
func (x *SecureResponse) Reset() {
*x = SecureResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_goadesign_goagen_service1_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SecureResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SecureResponse) ProtoMessage() {}
func (x *SecureResponse) ProtoReflect() protoreflect.Message {
mi := &file_goadesign_goagen_service1_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SecureResponse.ProtoReflect.Descriptor instead.
func (*SecureResponse) Descriptor() ([]byte, []int) {
return file_goadesign_goagen_service1_proto_rawDescGZIP(), []int{3}
}
func (x *SecureResponse) GetField() string {
if x != nil {
return x.Field
}
return ""
}
var File_goadesign_goagen_service1_proto protoreflect.FileDescriptor
var file_goadesign_goagen_service1_proto_rawDesc = []byte{
0x0a, 0x1f, 0x67, 0x6f, 0x61, 0x64, 0x65, 0x73, 0x69, 0x67, 0x6e, 0x5f, 0x67, 0x6f, 0x61, 0x67,
0x65, 0x6e, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x31, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x08, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x31, 0x22, 0x0f, 0x0a, 0x0d, 0x53,
0x69, 0x67, 0x6e, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x5c, 0x0a, 0x0e,
0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10,
0x0a, 0x03, 0x6a, 0x77, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6a, 0x77, 0x74,
0x12, 0x17, 0x0a, 0x07, 0x61, 0x70, 0x69, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28,
0x09, 0x52, 0x06, 0x61, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x12, 0x1f, 0x0a, 0x0b, 0x6f, 0x61, 0x75,
0x74, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
0x6f, 0x61, 0x75, 0x74, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x23, 0x0a, 0x0d, 0x53, 0x65,
0x63, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x66,
0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x66, 0x61, 0x69, 0x6c, 0x22,
0x26, 0x0a, 0x0e, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x14, 0x0a, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x05, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x32, 0x84, 0x01, 0x0a, 0x08, 0x53, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x31, 0x12, 0x3b, 0x0a, 0x06, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x12, 0x17,
0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x31, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x31, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x3b, 0x0a, 0x06, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x12, 0x17, 0x2e, 0x73, 0x65,
0x72, 0x76, 0x69, 0x63, 0x65, 0x31, 0x2e, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x31, 0x2e,
0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0d,
0x5a, 0x0b, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x31, 0x70, 0x62, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_goadesign_goagen_service1_proto_rawDescOnce sync.Once
file_goadesign_goagen_service1_proto_rawDescData = file_goadesign_goagen_service1_proto_rawDesc
)
func file_goadesign_goagen_service1_proto_rawDescGZIP() []byte {
file_goadesign_goagen_service1_proto_rawDescOnce.Do(func() {
file_goadesign_goagen_service1_proto_rawDescData = protoimpl.X.CompressGZIP(file_goadesign_goagen_service1_proto_rawDescData)
})
return file_goadesign_goagen_service1_proto_rawDescData
}
var file_goadesign_goagen_service1_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_goadesign_goagen_service1_proto_goTypes = []interface{}{
(*SigninRequest)(nil), // 0: service1.SigninRequest
(*SigninResponse)(nil), // 1: service1.SigninResponse
(*SecureRequest)(nil), // 2: service1.SecureRequest
(*SecureResponse)(nil), // 3: service1.SecureResponse
}
var file_goadesign_goagen_service1_proto_depIdxs = []int32{
0, // 0: service1.Service1.Signin:input_type -> service1.SigninRequest
2, // 1: service1.Service1.Secure:input_type -> service1.SecureRequest
1, // 2: service1.Service1.Signin:output_type -> service1.SigninResponse
3, // 3: service1.Service1.Secure:output_type -> service1.SecureResponse
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_goadesign_goagen_service1_proto_init() }
func file_goadesign_goagen_service1_proto_init() {
if File_goadesign_goagen_service1_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_goadesign_goagen_service1_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SigninRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_goadesign_goagen_service1_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SigninResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_goadesign_goagen_service1_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SecureRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_goadesign_goagen_service1_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SecureResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_goadesign_goagen_service1_proto_rawDesc,
NumEnums: 0,
NumMessages: 4,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_goadesign_goagen_service1_proto_goTypes,
DependencyIndexes: file_goadesign_goagen_service1_proto_depIdxs,
MessageInfos: file_goadesign_goagen_service1_proto_msgTypes,
}.Build()
File_goadesign_goagen_service1_proto = out.File
file_goadesign_goagen_service1_proto_rawDesc = nil
file_goadesign_goagen_service1_proto_goTypes = nil
file_goadesign_goagen_service1_proto_depIdxs = nil
}

View File

@@ -0,0 +1,42 @@
// Code generated with goa v3.6.0, DO NOT EDIT.
//
// Service1 protocol buffer definition
//
// Command:
// $ goa gen goa_example/design
syntax = "proto3";
package service1;
option go_package = "/service1pb";
// The secured service exposes endpoints that require valid authorization
// credentials.
service Service1 {
// Signin implements signin.
rpc Signin (SigninRequest) returns (SigninResponse);
// 这是一个需要JWT认证的接口
rpc Secure (SecureRequest) returns (SecureResponse);
}
message SigninRequest {
}
message SigninResponse {
// JWT token
string jwt = 1;
// API Key
string api_key = 2;
// OAuth2 token
string oauth_token = 3;
}
message SecureRequest {
// Whether to force auth failure even with a valid JWT
bool fail = 1;
}
message SecureResponse {
string field = 1;
}

View File

@@ -0,0 +1,145 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.19.4
// source: goadesign_goagen_service1.proto
package service1pb
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// Service1Client is the client API for Service1 service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type Service1Client interface {
// Signin implements signin.
Signin(ctx context.Context, in *SigninRequest, opts ...grpc.CallOption) (*SigninResponse, error)
// 这是一个需要JWT认证的接口
Secure(ctx context.Context, in *SecureRequest, opts ...grpc.CallOption) (*SecureResponse, error)
}
type service1Client struct {
cc grpc.ClientConnInterface
}
func NewService1Client(cc grpc.ClientConnInterface) Service1Client {
return &service1Client{cc}
}
func (c *service1Client) Signin(ctx context.Context, in *SigninRequest, opts ...grpc.CallOption) (*SigninResponse, error) {
out := new(SigninResponse)
err := c.cc.Invoke(ctx, "/service1.Service1/Signin", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *service1Client) Secure(ctx context.Context, in *SecureRequest, opts ...grpc.CallOption) (*SecureResponse, error) {
out := new(SecureResponse)
err := c.cc.Invoke(ctx, "/service1.Service1/Secure", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Service1Server is the server API for Service1 service.
// All implementations must embed UnimplementedService1Server
// for forward compatibility
type Service1Server interface {
// Signin implements signin.
Signin(context.Context, *SigninRequest) (*SigninResponse, error)
// 这是一个需要JWT认证的接口
Secure(context.Context, *SecureRequest) (*SecureResponse, error)
mustEmbedUnimplementedService1Server()
}
// UnimplementedService1Server must be embedded to have forward compatible implementations.
type UnimplementedService1Server struct {
}
func (UnimplementedService1Server) Signin(context.Context, *SigninRequest) (*SigninResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Signin not implemented")
}
func (UnimplementedService1Server) Secure(context.Context, *SecureRequest) (*SecureResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Secure not implemented")
}
func (UnimplementedService1Server) mustEmbedUnimplementedService1Server() {}
// UnsafeService1Server may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to Service1Server will
// result in compilation errors.
type UnsafeService1Server interface {
mustEmbedUnimplementedService1Server()
}
func RegisterService1Server(s grpc.ServiceRegistrar, srv Service1Server) {
s.RegisterService(&Service1_ServiceDesc, srv)
}
func _Service1_Signin_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SigninRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(Service1Server).Signin(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/service1.Service1/Signin",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(Service1Server).Signin(ctx, req.(*SigninRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Service1_Secure_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SecureRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(Service1Server).Secure(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/service1.Service1/Secure",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(Service1Server).Secure(ctx, req.(*SecureRequest))
}
return interceptor(ctx, in, info, handler)
}
// Service1_ServiceDesc is the grpc.ServiceDesc for Service1 service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Service1_ServiceDesc = grpc.ServiceDesc{
ServiceName: "service1.Service1",
HandlerType: (*Service1Server)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Signin",
Handler: _Service1_Signin_Handler,
},
{
MethodName: "Secure",
Handler: _Service1_Secure_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "goadesign_goagen_service1.proto",
}