commit b2e7135ad5e89f0e966c8137974d2c53409f5662 Author: wyhwyhwyh <573805736@qq.com> Date: Thu Jan 20 17:06:44 2022 +0800 代码相对完善 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68682a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.sum diff --git a/README.md b/README.md new file mode 100644 index 0000000..542ae90 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +### grpc-server + +- 获取组件 +- go get -u google.golang.org/grpc + +- 生成 pb 文件 +- protoc --proto_path=./protos ./protos/\*.proto --go_out=plugins=grpc:./pb + +- 生成 ssl 证书 +- cmd: openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj /CN=localhost + +- go1.15 之后需使用临时配置 添加扩展 SAN +- 临时配置 openssl.cnf 并使用 +- -config 指定配置文件 +- -extensions v3_req 扩展 +- cmd: openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj /CN=localhost -config ./openssl.cnf -extensions v3_req diff --git a/cert.pem b/cert.pem new file mode 100644 index 0000000..574dd62 --- /dev/null +++ b/cert.pem @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIE4TCCAsmgAwIBAgIUJC8WZ7nPROEEwjUJwJpwsUkHQu0wDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTIyMDEyMDA4MTE0MFoXDTIzMDEy +MDA4MTE0MFowFDESMBAGA1UEAwwJbG9jYWxob3N0MIICIjANBgkqhkiG9w0BAQEF +AAOCAg8AMIICCgKCAgEAuNwDPBdmTlGrZgVEnYkj0/ajuN7l/9JuoquRpjjSzTUR +2bIDL/eFQRBUYXPFVuZGep02obpEgi4bjPwLf2eCeHZOz2CP7UU8OynKh4V5fIge +rUKIpVtZ+IKvhfztvn5ObNK5b4nZCcb20wmNnQjn5LpjoMTT4ENTyYFUQ08Y31XF +NgnK6UQml86BNMWN7N6g19LjOna2xK/PDro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9JgB +VywTEb81V9qHQKHb9rt2kqYgS5S8khW7wJpI6u2S9Dz6JZKvlfdKj6Syuo0c2Uxo +S961yvqiDXGQDRu1rzF8+xFHpVENlDeN2lKHh+vDL36kACWgsozRWYnCEuxgcTwn +bWCuLo8VeA6VQuVQ53Gw5Pd+aOp/fQX0pobv1bdN1HsHwmozjY04mL/1BmMFBbXN +XgDF/7k= +-----END CERTIFICATE----- diff --git a/data.go b/data.go new file mode 100644 index 0000000..a822843 --- /dev/null +++ b/data.go @@ -0,0 +1,18 @@ +package main + +import "myschools.me/wyh/grpcservice/pb" + +var employees = []pb.Employee{ + { + Id: 1, + No: 1994, + FirstName: "chn", + LastName: "bin", + }, + { + Id: 2, + No: 1996, + FirstName: "wyh", + LastName: "zxf", + }, +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9532cc1 --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module myschools.me/wyh/grpcservice + +go 1.17 + +require ( + github.com/golang/protobuf v1.5.2 // indirect + golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d // indirect + golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect + golang.org/x/text v0.3.7 // indirect + google.golang.org/genproto v0.0.0-20220118154757-00ab72f36ad5 // indirect + google.golang.org/grpc v1.43.0 // indirect + google.golang.org/protobuf v1.27.1 // indirect +) diff --git a/key.pem b/key.pem new file mode 100644 index 0000000..483ce7d --- /dev/null +++ b/key.pem @@ -0,0 +1,52 @@ +-----BEGIN PRIVATE KEY----- +MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQC43AM8F2ZOUatm +BUSdiSPT9qO43uX/0m6iq5GmONLNNRHZsgMv94VBEFRhc8VW5kZ6nTahukSCLhuM +/At/Z4J4dk7PYI/tRTw7KcqHhXl8iB6tQoilW1n4gq+F/O2+fk5s0rlvidkJxvbT +CY2dCOfkumOgxNPgQ1PJgVRDTxjfVcU2CcrpRCaXzoE0xY3s3qDX0uM6drbEr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r91xd +9X75MveH93ycErkC6Xh652yVLLqlpwFGNBbiKoSkjrBJVhGY4CbUijx4OY32X/47 +36/Mqh4xMPmQojWciGEFL9ZqrFnKGxv+ckLYoSMCggEAJ+DQSJdLcsw/s73XJokB +qtfEoD0iwf7lNdkOrHBsoiFj49stIu/CcJRh+ijDdouZRTouKBt6T5uN9xOhk+P+ +M0XeejV/ttOOtpBZbHur9MMS3xp3M3BXqCorqxGU0IIKlnSd64au3rqdqi8x6l2f +Wk0yxShTHeb4wlSuImTdMoViCajXrl9zH0N8RdzpL8QmLUCwlkcqsnPcwrBAq/ZZ +qkNt8pyWcadXaPXmcgXgSr3h6x2taokHTb35O6A6ms+Y/slQGo7MxamgzVe+Q3Lf +96b1ac/K21mSenNgRaP6mR7vWPistqZaFmJn1A2tNdLd0M0pVsAMVPH/N4ILhSAp +bQKCAQEAi6kAq3RyexDcvaMuqheNjeiCVp0NcTbc3gzM0lDVHPIjhjEUpUj/9j8a +QMjC5wLqjPSDSQHDq8gSEzvS+InUpM9Z6C8e/tEa6O8WtrA6CQ8p1ewzwbIuUpCI +PbuUCnWKNGcvfgQNECC7XU/8wHTK3EA7RJJY/v/5q85oPoXWAqGdPaRgWZY0Dty4 +emi8yIzipsgaKWhh5AUghdoSQnzUEvaZwhMse/dztNAZXKTGcPJXRdmeExWLbbUO +4MQMLSWUcDBuQlgiSsdHAHmieiK0PXSxeiqwxWnnxML/7Fj8TB4T88Od26lEYUxD +tPbMW45EPgRyUxyKaQtIrUgBe8lvsg== +-----END PRIVATE KEY----- diff --git a/main.go b/main.go new file mode 100644 index 0000000..27f8036 --- /dev/null +++ b/main.go @@ -0,0 +1,107 @@ +package main + +import ( + "fmt" + "io" + "log" + "net" + "time" + + "golang.org/x/net/context" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/metadata" + + "myschools.me/wyh/grpcservice/pb" +) + +const ( + port = "8081" +) + +func main() { + listen, err := net.Listen("tcp", "0.0.0.0:"+port) + if err != nil { + log.Fatal("err: %s", err.Error()) + } + // 证书 + creds, err := credentials.NewServerTLSFromFile("cert.pem", "key.pem") + if err != nil { + log.Fatal("err: %s", err.Error()) + } + // 传递进grpc + options := []grpc.ServerOption{grpc.Creds(creds)} + // grpc服务 + server := grpc.NewServer(options...) + //服务注册 + pb.RegisterEmployeeServiceServer(server, new(employeeService)) + + log.Println("grpc server started..." + port) + + server.Serve(listen) +} + +type employeeService struct{} + +func (msg *employeeService) GetByNo(ctx context.Context, req *pb.GetByNoRequset) (*pb.EmployeeResponse, error) { + for _, e := range employees { + if req.No == e.No { + return &pb.EmployeeResponse{ + Employee: &e, + }, nil + } + } + return &pb.EmployeeResponse{}, nil +} + +func (msg *employeeService) GetAll(req *pb.GetAllRequest, steam pb.EmployeeService_GetAllServer) error { + for _, e := range employees { + + steam.Send(&pb.EmployeeResponse{ + Employee: &e, + }) + time.Sleep(2 * time.Second) + + } + return nil +} +func (msg *employeeService) AddPhoto(stream pb.EmployeeService_AddPhotoServer) error { + md, ok := metadata.FromIncomingContext(stream.Context()) + if ok { + fmt.Println("employee", md["no"][0]) + } + img := []byte{} + for { + data, err := stream.Recv() + if err == io.EOF { + fmt.Printf("file size:%d\n", len(img)) + return stream.SendAndClose(&pb.AddPhotoResponse{IsOk: true}) + } + if err != nil { + return err + } + fmt.Printf("file received: %d", len(data.Data)) + img = append(img, data.Data...) + } + return nil +} +func (msg *employeeService) Save(context.Context, *pb.EmployeeRequest) (*pb.EmployeeResponse, error) { + return nil, nil +} +func (msg *employeeService) SaveAll(stream pb.EmployeeService_SaveAllServer) error { + for { + emp, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + return err + } + employees = append(employees, *emp.Employee) + stream.Send(&pb.EmployeeResponse{Employee: emp.Employee}) + } + for _, emp := range employees { + fmt.Println(emp) + } + return nil +} diff --git a/openssl.cnf b/openssl.cnf new file mode 100644 index 0000000..9c6cc70 --- /dev/null +++ b/openssl.cnf @@ -0,0 +1,357 @@ +# +# OpenSSL example configuration file. +# This is mostly being used for generation of certificate requests. +# + +# Note that you can include other files from the main configuration +# file using the .include directive. +#.include filename + +# This definition stops the following lines choking if HOME isn't +# defined. +HOME = . + +# Extra OBJECT IDENTIFIER info: +#oid_file = $ENV::HOME/.oid +oid_section = new_oids + +# To use this configuration file with the "-extfile" option of the +# "openssl x509" utility, name here the section containing the +# X.509v3 extensions to use: +# extensions = +# (Alternatively, use a configuration file that has only +# X.509v3 extensions in its main [= default] section.) + +[ new_oids ] + +# We can add new OIDs in here for use by 'ca', 'req' and 'ts'. +# Add a simple OID like this: +# testoid1=1.2.3.4 +# Or use config file substitution like this: +# testoid2=${testoid1}.5.6 + +# Policies used by the TSA examples. +tsa_policy1 = 1.2.3.4.1 +tsa_policy2 = 1.2.3.4.5.6 +tsa_policy3 = 1.2.3.4.5.7 + +#################################################################### +[ ca ] +default_ca = CA_default # The default ca section + +#################################################################### +[ CA_default ] + +dir = ./demoCA # Where everything is kept +certs = $dir/certs # Where the issued certs are kept +crl_dir = $dir/crl # Where the issued crl are kept +database = $dir/index.txt # database index file. +#unique_subject = no # Set to 'no' to allow creation of + # several certs with same subject. +new_certs_dir = $dir/newcerts # default place for new certs. + +certificate = $dir/cacert.pem # The CA certificate +serial = $dir/serial # The current serial number +crlnumber = $dir/crlnumber # the current crl number + # must be commented out to leave a V1 CRL +crl = $dir/crl.pem # The current CRL +private_key = $dir/private/cakey.pem# The private key + +x509_extensions = usr_cert # The extensions to add to the cert + +# Comment out the following two lines for the "traditional" +# (and highly broken) format. +name_opt = ca_default # Subject Name options +cert_opt = ca_default # Certificate field options + +# Extension copying option: use with caution. +copy_extensions = copy + +# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs +# so this is commented out by default to leave a V1 CRL. +# crlnumber must also be commented out to leave a V1 CRL. +# crl_extensions = crl_ext + +default_days = 365 # how long to certify for +default_crl_days= 30 # how long before next CRL +default_md = default # use public key default MD +preserve = no # keep passed DN ordering + +# A few difference way of specifying how similar the request should look +# For type CA, the listed attributes must be the same, and the optional +# and supplied fields are just that :-) +policy = policy_match + +# For the CA policy +[ policy_match ] +countryName = match +stateOrProvinceName = match +organizationName = match +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +# For the 'anything' policy +# At this point in time, you must list all acceptable 'object' +# types. +[ policy_anything ] +countryName = optional +stateOrProvinceName = optional +localityName = optional +organizationName = optional +organizationalUnitName = optional +commonName = supplied +emailAddress = optional + +#################################################################### +[ req ] +default_bits = 2048 +default_keyfile = privkey.pem +distinguished_name = req_distinguished_name +attributes = req_attributes +x509_extensions = v3_ca # The extensions to add to the self signed cert + +# Passwords for private keys if not present they will be prompted for +# input_password = secret +# output_password = secret + +# This sets a mask for permitted string types. There are several options. +# default: PrintableString, T61String, BMPString. +# pkix : PrintableString, BMPString (PKIX recommendation before 2004) +# utf8only: only UTF8Strings (PKIX recommendation after 2004). +# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). +# MASK:XXXX a literal mask value. +# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. +string_mask = utf8only + +req_extensions = v3_req # The extensions to add to a certificate request + +[ req_distinguished_name ] +countryName = Country Name (2 letter code) +countryName_default = AU +countryName_min = 2 +countryName_max = 2 + +stateOrProvinceName = State or Province Name (full name) +stateOrProvinceName_default = Some-State + +localityName = Locality Name (eg, city) + +0.organizationName = Organization Name (eg, company) +0.organizationName_default = Internet Widgits Pty Ltd + +# we can do this but it is not needed normally :-) +#1.organizationName = Second Organization Name (eg, company) +#1.organizationName_default = World Wide Web Pty Ltd + +organizationalUnitName = Organizational Unit Name (eg, section) +#organizationalUnitName_default = + +commonName = Common Name (e.g. server FQDN or YOUR name) +commonName_max = 64 + +emailAddress = Email Address +emailAddress_max = 64 + +# SET-ex3 = SET extension number 3 + +[ req_attributes ] +challengePassword = A challenge password +challengePassword_min = 4 +challengePassword_max = 20 + +unstructuredName = An optional company name + +[ usr_cert ] + +# These extensions are added when 'ca' signs a request. + +# This goes against PKIX guidelines but some CAs do it and some software +# requires this to avoid interpreting an end user certificate as a CA. + +basicConstraints=CA:FALSE + +# Here are some examples of the usage of nsCertType. If it is omitted +# the certificate can be used for anything *except* object signing. + +# This is OK for an SSL server. +# nsCertType = server + +# For an object signing certificate this would be used. +# nsCertType = objsign + +# For normal client use this is typical +# nsCertType = client, email + +# and for everything including object signing: +# nsCertType = client, email, objsign + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid,issuer + +# This stuff is for subjectAltName and issuerAltname. +# Import the email address. +# subjectAltName=email:copy +# An alternative to produce certificates that aren't +# deprecated according to PKIX. +# subjectAltName=email:move + +# Copy subject details +# issuerAltName=issuer:copy + +#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem +#nsBaseUrl +#nsRevocationUrl +#nsRenewalUrl +#nsCaPolicyUrl +#nsSslServerName + +# This is required for TSA certificates. +# extendedKeyUsage = critical,timeStamping + +[ v3_req ] + +# Extensions to add to a certificate request + +basicConstraints = CA:FALSE +keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +subjectAltName = @alt_names + + +[ alt_names ] +DNS.1 = * +DNS.2 = * + +[ v3_ca ] + + +# Extensions for a typical CA + + +# PKIX recommendation. + +subjectKeyIdentifier=hash + +authorityKeyIdentifier=keyid:always,issuer + +basicConstraints = critical,CA:true + +# Key usage: this is typical for a CA certificate. However since it will +# prevent it being used as an test self-signed certificate it is best +# left out by default. +# keyUsage = cRLSign, keyCertSign + +# Some might want this also +# nsCertType = sslCA, emailCA + +# Include email address in subject alt name: another PKIX recommendation +# subjectAltName=email:copy +# Copy issuer details +# issuerAltName=issuer:copy + +# DER hex encoding of an extension: beware experts only! +# obj=DER:02:03 +# Where 'obj' is a standard or added object +# You can even override a supported extension: +# basicConstraints= critical, DER:30:03:01:01:FF + +[ crl_ext ] + +# CRL extensions. +# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL. + +# issuerAltName=issuer:copy +authorityKeyIdentifier=keyid:always + +[ proxy_cert_ext ] +# These extensions should be added when creating a proxy certificate + +# This goes against PKIX guidelines but some CAs do it and some software +# requires this to avoid interpreting an end user certificate as a CA. + +basicConstraints=CA:FALSE + +# Here are some examples of the usage of nsCertType. If it is omitted +# the certificate can be used for anything *except* object signing. + +# This is OK for an SSL server. +# nsCertType = server + +# For an object signing certificate this would be used. +# nsCertType = objsign + +# For normal client use this is typical +# nsCertType = client, email + +# and for everything including object signing: +# nsCertType = client, email, objsign + +# This is typical in keyUsage for a client certificate. +# keyUsage = nonRepudiation, digitalSignature, keyEncipherment + +# This will be displayed in Netscape's comment listbox. +nsComment = "OpenSSL Generated Certificate" + +# PKIX recommendations harmless if included in all certificates. +subjectKeyIdentifier=hash +authorityKeyIdentifier=keyid,issuer + +# This stuff is for subjectAltName and issuerAltname. +# Import the email address. +# subjectAltName=email:copy +# An alternative to produce certificates that aren't +# deprecated according to PKIX. +# subjectAltName=email:move + +# Copy subject details +# issuerAltName=issuer:copy + +#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem +#nsBaseUrl +#nsRevocationUrl +#nsRenewalUrl +#nsCaPolicyUrl +#nsSslServerName + +# This really needs to be in place for it to be a proxy certificate. +proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo + +#################################################################### +[ tsa ] + +default_tsa = tsa_config1 # the default TSA section + +[ tsa_config1 ] + +# These are used by the TSA reply generation only. +dir = ./demoCA # TSA root directory +serial = $dir/tsaserial # The current serial number (mandatory) +crypto_device = builtin # OpenSSL engine to use for signing +signer_cert = $dir/tsacert.pem # The TSA signing certificate + # (optional) +certs = $dir/cacert.pem # Certificate chain to include in reply + # (optional) +signer_key = $dir/private/tsakey.pem # The TSA private key (optional) +signer_digest = sha256 # Signing digest to use. (Optional) +default_policy = tsa_policy1 # Policy if request did not specify it + # (optional) +other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional) +digests = sha1, sha256, sha384, sha512 # Acceptable message digests (mandatory) +accuracy = secs:1, millisecs:500, microsecs:100 # (optional) +clock_precision_digits = 0 # number of digits after dot. (optional) +ordering = yes # Is ordering defined for timestamps? + # (optional, default: no) +tsa_name = yes # Must the TSA name be included in the reply? + # (optional, default: no) +ess_cert_id_chain = no # Must the ESS cert id chain be included? + # (optional, default: no) +ess_cert_id_alg = sha1 # algorithm to compute certificate + # identifier (optional, default: sha1) diff --git a/pb/enums.pb.go b/pb/enums.pb.go new file mode 100644 index 0000000..35ae3b8 --- /dev/null +++ b/pb/enums.pb.go @@ -0,0 +1,134 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.3 +// source: enums.proto + +package pb + +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 EmployeeStatus int32 + +const ( + EmployeeStatus_NORMAL EmployeeStatus = 0 + EmployeeStatus_ON_VACATION EmployeeStatus = 1 + EmployeeStatus_RESIGNED EmployeeStatus = 2 + EmployeeStatus_RETIRED EmployeeStatus = 3 +) + +// Enum value maps for EmployeeStatus. +var ( + EmployeeStatus_name = map[int32]string{ + 0: "NORMAL", + 1: "ON_VACATION", + 2: "RESIGNED", + 3: "RETIRED", + } + EmployeeStatus_value = map[string]int32{ + "NORMAL": 0, + "ON_VACATION": 1, + "RESIGNED": 2, + "RETIRED": 3, + } +) + +func (x EmployeeStatus) Enum() *EmployeeStatus { + p := new(EmployeeStatus) + *p = x + return p +} + +func (x EmployeeStatus) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (EmployeeStatus) Descriptor() protoreflect.EnumDescriptor { + return file_enums_proto_enumTypes[0].Descriptor() +} + +func (EmployeeStatus) Type() protoreflect.EnumType { + return &file_enums_proto_enumTypes[0] +} + +func (x EmployeeStatus) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use EmployeeStatus.Descriptor instead. +func (EmployeeStatus) EnumDescriptor() ([]byte, []int) { + return file_enums_proto_rawDescGZIP(), []int{0} +} + +var File_enums_proto protoreflect.FileDescriptor + +var file_enums_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2a, 0x48, 0x0a, + 0x0e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x0a, 0x0a, 0x06, 0x4e, 0x4f, 0x52, 0x4d, 0x41, 0x4c, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x4f, + 0x4e, 0x5f, 0x56, 0x41, 0x43, 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, + 0x52, 0x45, 0x53, 0x49, 0x47, 0x4e, 0x45, 0x44, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x52, 0x45, + 0x54, 0x49, 0x52, 0x45, 0x44, 0x10, 0x03, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x2f, 0x3b, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_enums_proto_rawDescOnce sync.Once + file_enums_proto_rawDescData = file_enums_proto_rawDesc +) + +func file_enums_proto_rawDescGZIP() []byte { + file_enums_proto_rawDescOnce.Do(func() { + file_enums_proto_rawDescData = protoimpl.X.CompressGZIP(file_enums_proto_rawDescData) + }) + return file_enums_proto_rawDescData +} + +var file_enums_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_enums_proto_goTypes = []interface{}{ + (EmployeeStatus)(0), // 0: EmployeeStatus +} +var file_enums_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] 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_enums_proto_init() } +func file_enums_proto_init() { + if File_enums_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_enums_proto_rawDesc, + NumEnums: 1, + NumMessages: 0, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_enums_proto_goTypes, + DependencyIndexes: file_enums_proto_depIdxs, + EnumInfos: file_enums_proto_enumTypes, + }.Build() + File_enums_proto = out.File + file_enums_proto_rawDesc = nil + file_enums_proto_goTypes = nil + file_enums_proto_depIdxs = nil +} diff --git a/pb/message.pb.go b/pb/message.pb.go new file mode 100644 index 0000000..ef1c8ef --- /dev/null +++ b/pb/message.pb.go @@ -0,0 +1,895 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.19.3 +// source: message.proto + +package pb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + 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 Employee struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + No int32 `protobuf:"varint,2,opt,name=no,proto3" json:"no,omitempty"` + FirstName string `protobuf:"bytes,3,opt,name=firstName,proto3" json:"firstName,omitempty"` + LastName string `protobuf:"bytes,4,opt,name=lastName,proto3" json:"lastName,omitempty"` + Salary float32 `protobuf:"fixed32,5,opt,name=salary,proto3" json:"salary,omitempty"` +} + +func (x *Employee) Reset() { + *x = Employee{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Employee) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Employee) ProtoMessage() {} + +func (x *Employee) ProtoReflect() protoreflect.Message { + mi := &file_message_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 Employee.ProtoReflect.Descriptor instead. +func (*Employee) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0} +} + +func (x *Employee) GetId() int32 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *Employee) GetNo() int32 { + if x != nil { + return x.No + } + return 0 +} + +func (x *Employee) GetFirstName() string { + if x != nil { + return x.FirstName + } + return "" +} + +func (x *Employee) GetLastName() string { + if x != nil { + return x.LastName + } + return "" +} + +func (x *Employee) GetSalary() float32 { + if x != nil { + return x.Salary + } + return 0 +} + +type GetByNoRequset struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + No int32 `protobuf:"varint,1,opt,name=no,proto3" json:"no,omitempty"` +} + +func (x *GetByNoRequset) Reset() { + *x = GetByNoRequset{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetByNoRequset) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetByNoRequset) ProtoMessage() {} + +func (x *GetByNoRequset) ProtoReflect() protoreflect.Message { + mi := &file_message_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 GetByNoRequset.ProtoReflect.Descriptor instead. +func (*GetByNoRequset) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{1} +} + +func (x *GetByNoRequset) GetNo() int32 { + if x != nil { + return x.No + } + return 0 +} + +type EmployeeResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Employee *Employee `protobuf:"bytes,1,opt,name=employee,proto3" json:"employee,omitempty"` +} + +func (x *EmployeeResponse) Reset() { + *x = EmployeeResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EmployeeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EmployeeResponse) ProtoMessage() {} + +func (x *EmployeeResponse) ProtoReflect() protoreflect.Message { + mi := &file_message_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 EmployeeResponse.ProtoReflect.Descriptor instead. +func (*EmployeeResponse) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{2} +} + +func (x *EmployeeResponse) GetEmployee() *Employee { + if x != nil { + return x.Employee + } + return nil +} + +type GetAllRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetAllRequest) Reset() { + *x = GetAllRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetAllRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetAllRequest) ProtoMessage() {} + +func (x *GetAllRequest) ProtoReflect() protoreflect.Message { + mi := &file_message_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 GetAllRequest.ProtoReflect.Descriptor instead. +func (*GetAllRequest) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{3} +} + +type AddPhotoRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` +} + +func (x *AddPhotoRequest) Reset() { + *x = AddPhotoRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AddPhotoRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddPhotoRequest) ProtoMessage() {} + +func (x *AddPhotoRequest) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[4] + 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 AddPhotoRequest.ProtoReflect.Descriptor instead. +func (*AddPhotoRequest) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{4} +} + +func (x *AddPhotoRequest) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +type AddPhotoResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IsOk bool `protobuf:"varint,1,opt,name=isOk,proto3" json:"isOk,omitempty"` +} + +func (x *AddPhotoResponse) Reset() { + *x = AddPhotoResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AddPhotoResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddPhotoResponse) ProtoMessage() {} + +func (x *AddPhotoResponse) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[5] + 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 AddPhotoResponse.ProtoReflect.Descriptor instead. +func (*AddPhotoResponse) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{5} +} + +func (x *AddPhotoResponse) GetIsOk() bool { + if x != nil { + return x.IsOk + } + return false +} + +type EmployeeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Employee *Employee `protobuf:"bytes,1,opt,name=employee,proto3" json:"employee,omitempty"` +} + +func (x *EmployeeRequest) Reset() { + *x = EmployeeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EmployeeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EmployeeRequest) ProtoMessage() {} + +func (x *EmployeeRequest) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[6] + 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 EmployeeRequest.ProtoReflect.Descriptor instead. +func (*EmployeeRequest) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{6} +} + +func (x *EmployeeRequest) GetEmployee() *Employee { + if x != nil { + return x.Employee + } + return nil +} + +var File_message_proto protoreflect.FileDescriptor + +var file_message_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x7c, 0x0a, 0x08, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x6e, + 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6e, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x66, + 0x69, 0x72, 0x73, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x66, 0x69, 0x72, 0x73, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x73, + 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x61, 0x73, + 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x61, 0x6c, 0x61, 0x72, 0x79, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x02, 0x52, 0x06, 0x73, 0x61, 0x6c, 0x61, 0x72, 0x79, 0x22, 0x20, 0x0a, + 0x0e, 0x47, 0x65, 0x74, 0x42, 0x79, 0x4e, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x73, 0x65, 0x74, 0x12, + 0x0e, 0x0a, 0x02, 0x6e, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6e, 0x6f, 0x22, + 0x39, 0x0a, 0x10, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x08, 0x65, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, + 0x52, 0x08, 0x65, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x22, 0x0f, 0x0a, 0x0d, 0x47, 0x65, + 0x74, 0x41, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x25, 0x0a, 0x0f, 0x41, + 0x64, 0x64, 0x50, 0x68, 0x6f, 0x74, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, + 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, + 0x74, 0x61, 0x22, 0x26, 0x0a, 0x10, 0x41, 0x64, 0x64, 0x50, 0x68, 0x6f, 0x74, 0x6f, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x69, 0x73, 0x4f, 0x6b, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x69, 0x73, 0x4f, 0x6b, 0x22, 0x38, 0x0a, 0x0f, 0x45, 0x6d, + 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x25, 0x0a, + 0x08, 0x65, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x09, 0x2e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, 0x08, 0x65, 0x6d, 0x70, 0x6c, + 0x6f, 0x79, 0x65, 0x65, 0x32, 0x83, 0x02, 0x0a, 0x0f, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, + 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2d, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x42, + 0x79, 0x4e, 0x6f, 0x12, 0x0f, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x79, 0x4e, 0x6f, 0x52, 0x65, 0x71, + 0x75, 0x73, 0x65, 0x74, 0x1a, 0x11, 0x2e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2d, 0x0a, 0x06, 0x47, 0x65, 0x74, 0x41, 0x6c, + 0x6c, 0x12, 0x0e, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x11, 0x2e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x31, 0x0a, 0x08, 0x41, 0x64, 0x64, 0x50, 0x68, 0x6f, + 0x74, 0x6f, 0x12, 0x10, 0x2e, 0x41, 0x64, 0x64, 0x50, 0x68, 0x6f, 0x74, 0x6f, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x41, 0x64, 0x64, 0x50, 0x68, 0x6f, 0x74, 0x6f, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x12, 0x2b, 0x0a, 0x04, 0x53, 0x61, 0x76, + 0x65, 0x12, 0x10, 0x2e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x32, 0x0a, 0x07, 0x53, 0x61, 0x76, 0x65, 0x41, 0x6c, + 0x6c, 0x12, 0x10, 0x2e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x45, 0x6d, 0x70, 0x6c, 0x6f, 0x79, 0x65, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x2f, + 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_message_proto_rawDescOnce sync.Once + file_message_proto_rawDescData = file_message_proto_rawDesc +) + +func file_message_proto_rawDescGZIP() []byte { + file_message_proto_rawDescOnce.Do(func() { + file_message_proto_rawDescData = protoimpl.X.CompressGZIP(file_message_proto_rawDescData) + }) + return file_message_proto_rawDescData +} + +var file_message_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_message_proto_goTypes = []interface{}{ + (*Employee)(nil), // 0: Employee + (*GetByNoRequset)(nil), // 1: GetByNoRequset + (*EmployeeResponse)(nil), // 2: EmployeeResponse + (*GetAllRequest)(nil), // 3: GetAllRequest + (*AddPhotoRequest)(nil), // 4: AddPhotoRequest + (*AddPhotoResponse)(nil), // 5: AddPhotoResponse + (*EmployeeRequest)(nil), // 6: EmployeeRequest +} +var file_message_proto_depIdxs = []int32{ + 0, // 0: EmployeeResponse.employee:type_name -> Employee + 0, // 1: EmployeeRequest.employee:type_name -> Employee + 1, // 2: EmployeeService.GetByNo:input_type -> GetByNoRequset + 3, // 3: EmployeeService.GetAll:input_type -> GetAllRequest + 4, // 4: EmployeeService.AddPhoto:input_type -> AddPhotoRequest + 6, // 5: EmployeeService.Save:input_type -> EmployeeRequest + 6, // 6: EmployeeService.SaveAll:input_type -> EmployeeRequest + 2, // 7: EmployeeService.GetByNo:output_type -> EmployeeResponse + 2, // 8: EmployeeService.GetAll:output_type -> EmployeeResponse + 5, // 9: EmployeeService.AddPhoto:output_type -> AddPhotoResponse + 2, // 10: EmployeeService.Save:output_type -> EmployeeResponse + 2, // 11: EmployeeService.SaveAll:output_type -> EmployeeResponse + 7, // [7:12] is the sub-list for method output_type + 2, // [2:7] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_message_proto_init() } +func file_message_proto_init() { + if File_message_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Employee); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetByNoRequset); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EmployeeResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetAllRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AddPhotoRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AddPhotoResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_message_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EmployeeRequest); 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_message_proto_rawDesc, + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_message_proto_goTypes, + DependencyIndexes: file_message_proto_depIdxs, + MessageInfos: file_message_proto_msgTypes, + }.Build() + File_message_proto = out.File + file_message_proto_rawDesc = nil + file_message_proto_goTypes = nil + file_message_proto_depIdxs = nil +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// EmployeeServiceClient is the client API for EmployeeService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type EmployeeServiceClient interface { + GetByNo(ctx context.Context, in *GetByNoRequset, opts ...grpc.CallOption) (*EmployeeResponse, error) + GetAll(ctx context.Context, in *GetAllRequest, opts ...grpc.CallOption) (EmployeeService_GetAllClient, error) + AddPhoto(ctx context.Context, opts ...grpc.CallOption) (EmployeeService_AddPhotoClient, error) + Save(ctx context.Context, in *EmployeeRequest, opts ...grpc.CallOption) (*EmployeeResponse, error) + SaveAll(ctx context.Context, opts ...grpc.CallOption) (EmployeeService_SaveAllClient, error) +} + +type employeeServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewEmployeeServiceClient(cc grpc.ClientConnInterface) EmployeeServiceClient { + return &employeeServiceClient{cc} +} + +func (c *employeeServiceClient) GetByNo(ctx context.Context, in *GetByNoRequset, opts ...grpc.CallOption) (*EmployeeResponse, error) { + out := new(EmployeeResponse) + err := c.cc.Invoke(ctx, "/EmployeeService/GetByNo", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *employeeServiceClient) GetAll(ctx context.Context, in *GetAllRequest, opts ...grpc.CallOption) (EmployeeService_GetAllClient, error) { + stream, err := c.cc.NewStream(ctx, &_EmployeeService_serviceDesc.Streams[0], "/EmployeeService/GetAll", opts...) + if err != nil { + return nil, err + } + x := &employeeServiceGetAllClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type EmployeeService_GetAllClient interface { + Recv() (*EmployeeResponse, error) + grpc.ClientStream +} + +type employeeServiceGetAllClient struct { + grpc.ClientStream +} + +func (x *employeeServiceGetAllClient) Recv() (*EmployeeResponse, error) { + m := new(EmployeeResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *employeeServiceClient) AddPhoto(ctx context.Context, opts ...grpc.CallOption) (EmployeeService_AddPhotoClient, error) { + stream, err := c.cc.NewStream(ctx, &_EmployeeService_serviceDesc.Streams[1], "/EmployeeService/AddPhoto", opts...) + if err != nil { + return nil, err + } + x := &employeeServiceAddPhotoClient{stream} + return x, nil +} + +type EmployeeService_AddPhotoClient interface { + Send(*AddPhotoRequest) error + CloseAndRecv() (*AddPhotoResponse, error) + grpc.ClientStream +} + +type employeeServiceAddPhotoClient struct { + grpc.ClientStream +} + +func (x *employeeServiceAddPhotoClient) Send(m *AddPhotoRequest) error { + return x.ClientStream.SendMsg(m) +} + +func (x *employeeServiceAddPhotoClient) CloseAndRecv() (*AddPhotoResponse, error) { + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + m := new(AddPhotoResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *employeeServiceClient) Save(ctx context.Context, in *EmployeeRequest, opts ...grpc.CallOption) (*EmployeeResponse, error) { + out := new(EmployeeResponse) + err := c.cc.Invoke(ctx, "/EmployeeService/Save", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *employeeServiceClient) SaveAll(ctx context.Context, opts ...grpc.CallOption) (EmployeeService_SaveAllClient, error) { + stream, err := c.cc.NewStream(ctx, &_EmployeeService_serviceDesc.Streams[2], "/EmployeeService/SaveAll", opts...) + if err != nil { + return nil, err + } + x := &employeeServiceSaveAllClient{stream} + return x, nil +} + +type EmployeeService_SaveAllClient interface { + Send(*EmployeeRequest) error + Recv() (*EmployeeResponse, error) + grpc.ClientStream +} + +type employeeServiceSaveAllClient struct { + grpc.ClientStream +} + +func (x *employeeServiceSaveAllClient) Send(m *EmployeeRequest) error { + return x.ClientStream.SendMsg(m) +} + +func (x *employeeServiceSaveAllClient) Recv() (*EmployeeResponse, error) { + m := new(EmployeeResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// EmployeeServiceServer is the server API for EmployeeService service. +type EmployeeServiceServer interface { + GetByNo(context.Context, *GetByNoRequset) (*EmployeeResponse, error) + GetAll(*GetAllRequest, EmployeeService_GetAllServer) error + AddPhoto(EmployeeService_AddPhotoServer) error + Save(context.Context, *EmployeeRequest) (*EmployeeResponse, error) + SaveAll(EmployeeService_SaveAllServer) error +} + +// UnimplementedEmployeeServiceServer can be embedded to have forward compatible implementations. +type UnimplementedEmployeeServiceServer struct { +} + +func (*UnimplementedEmployeeServiceServer) GetByNo(context.Context, *GetByNoRequset) (*EmployeeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetByNo not implemented") +} +func (*UnimplementedEmployeeServiceServer) GetAll(*GetAllRequest, EmployeeService_GetAllServer) error { + return status.Errorf(codes.Unimplemented, "method GetAll not implemented") +} +func (*UnimplementedEmployeeServiceServer) AddPhoto(EmployeeService_AddPhotoServer) error { + return status.Errorf(codes.Unimplemented, "method AddPhoto not implemented") +} +func (*UnimplementedEmployeeServiceServer) Save(context.Context, *EmployeeRequest) (*EmployeeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Save not implemented") +} +func (*UnimplementedEmployeeServiceServer) SaveAll(EmployeeService_SaveAllServer) error { + return status.Errorf(codes.Unimplemented, "method SaveAll not implemented") +} + +func RegisterEmployeeServiceServer(s *grpc.Server, srv EmployeeServiceServer) { + s.RegisterService(&_EmployeeService_serviceDesc, srv) +} + +func _EmployeeService_GetByNo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetByNoRequset) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EmployeeServiceServer).GetByNo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/EmployeeService/GetByNo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EmployeeServiceServer).GetByNo(ctx, req.(*GetByNoRequset)) + } + return interceptor(ctx, in, info, handler) +} + +func _EmployeeService_GetAll_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(GetAllRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(EmployeeServiceServer).GetAll(m, &employeeServiceGetAllServer{stream}) +} + +type EmployeeService_GetAllServer interface { + Send(*EmployeeResponse) error + grpc.ServerStream +} + +type employeeServiceGetAllServer struct { + grpc.ServerStream +} + +func (x *employeeServiceGetAllServer) Send(m *EmployeeResponse) error { + return x.ServerStream.SendMsg(m) +} + +func _EmployeeService_AddPhoto_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(EmployeeServiceServer).AddPhoto(&employeeServiceAddPhotoServer{stream}) +} + +type EmployeeService_AddPhotoServer interface { + SendAndClose(*AddPhotoResponse) error + Recv() (*AddPhotoRequest, error) + grpc.ServerStream +} + +type employeeServiceAddPhotoServer struct { + grpc.ServerStream +} + +func (x *employeeServiceAddPhotoServer) SendAndClose(m *AddPhotoResponse) error { + return x.ServerStream.SendMsg(m) +} + +func (x *employeeServiceAddPhotoServer) Recv() (*AddPhotoRequest, error) { + m := new(AddPhotoRequest) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func _EmployeeService_Save_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmployeeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(EmployeeServiceServer).Save(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/EmployeeService/Save", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EmployeeServiceServer).Save(ctx, req.(*EmployeeRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _EmployeeService_SaveAll_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(EmployeeServiceServer).SaveAll(&employeeServiceSaveAllServer{stream}) +} + +type EmployeeService_SaveAllServer interface { + Send(*EmployeeResponse) error + Recv() (*EmployeeRequest, error) + grpc.ServerStream +} + +type employeeServiceSaveAllServer struct { + grpc.ServerStream +} + +func (x *employeeServiceSaveAllServer) Send(m *EmployeeResponse) error { + return x.ServerStream.SendMsg(m) +} + +func (x *employeeServiceSaveAllServer) Recv() (*EmployeeRequest, error) { + m := new(EmployeeRequest) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +var _EmployeeService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "EmployeeService", + HandlerType: (*EmployeeServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetByNo", + Handler: _EmployeeService_GetByNo_Handler, + }, + { + MethodName: "Save", + Handler: _EmployeeService_Save_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "GetAll", + Handler: _EmployeeService_GetAll_Handler, + ServerStreams: true, + }, + { + StreamName: "AddPhoto", + Handler: _EmployeeService_AddPhoto_Handler, + ClientStreams: true, + }, + { + StreamName: "SaveAll", + Handler: _EmployeeService_SaveAll_Handler, + ServerStreams: true, + ClientStreams: true, + }, + }, + Metadata: "message.proto", +} diff --git a/protos/enums.proto b/protos/enums.proto new file mode 100644 index 0000000..9ff0c1f --- /dev/null +++ b/protos/enums.proto @@ -0,0 +1,10 @@ +syntax ="proto3"; + +option go_package="./;pb"; + +enum EmployeeStatus { + NORMAL=0; + ON_VACATION=1; + RESIGNED=2; + RETIRED=3; +} \ No newline at end of file diff --git a/protos/message.proto b/protos/message.proto new file mode 100644 index 0000000..2275778 --- /dev/null +++ b/protos/message.proto @@ -0,0 +1,41 @@ +syntax="proto3"; + +option go_package="./;pb"; + +message Employee { + int32 id=1; + int32 no=2; + string firstName=3; + string lastName=4; + float salary=5; +} + +message GetByNoRequset { + int32 no =1; +} + +message EmployeeResponse { + Employee employee=1; +} + +message GetAllRequest{} + +message AddPhotoRequest{ + bytes data=1; +} + +message AddPhotoResponse { + bool isOk=1; +} + +message EmployeeRequest { + Employee employee=1; +} + +service EmployeeService { + rpc GetByNo(GetByNoRequset) returns (EmployeeResponse); + rpc GetAll(GetAllRequest) returns (stream EmployeeResponse); + rpc AddPhoto(stream AddPhotoRequest) returns (AddPhotoResponse); + rpc Save(EmployeeRequest) returns (EmployeeResponse); + rpc SaveAll(stream EmployeeRequest) returns (stream EmployeeResponse); +} \ No newline at end of file diff --git a/service/service.go b/service/service.go new file mode 100644 index 0000000..6d43c33 --- /dev/null +++ b/service/service.go @@ -0,0 +1 @@ +package service