initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
FROM golang:1.11 AS builder
ENV CGO_ENABLED 0
ENV GOOS linux
WORKDIR $GOPATH/src/zero
COPY . .
RUN go build -ldflags="-s -w" -o /app/unaryproxy example/rpc/proxy/proxy.go
FROM alpine
WORKDIR /app
COPY --from=builder /app/unaryproxy /app/unaryproxy
CMD ["./unaryproxy"]

View File

@@ -0,0 +1,50 @@
package main
import (
"context"
"flag"
"zero/core/logx"
"zero/core/service"
"zero/example/rpc/remote/unary"
"zero/rpcx"
"google.golang.org/grpc"
)
var (
listen = flag.String("listen", "0.0.0.0:3456", "the address to listen on")
server = flag.String("server", "dns:///unaryserver:3456", "the backend service")
)
type GreetServer struct {
*rpcx.RpcProxy
}
func (s *GreetServer) Greet(ctx context.Context, req *unary.Request) (*unary.Response, error) {
conn, err := s.TakeConn(ctx)
if err != nil {
return nil, err
}
remote := unary.NewGreeterClient(conn)
return remote.Greet(ctx, req)
}
func main() {
flag.Parse()
proxy := rpcx.MustNewServer(rpcx.RpcServerConf{
ServiceConf: service.ServiceConf{
Log: logx.LogConf{
Mode: "console",
},
},
ListenOn: *listen,
}, func(grpcServer *grpc.Server) {
unary.RegisterGreeterServer(grpcServer, &GreetServer{
RpcProxy: rpcx.NewRpcProxy(*server),
})
})
proxy.Start()
}

View File

@@ -0,0 +1,46 @@
apiVersion: v1
kind: Service
metadata:
name: unaryproxy
namespace: kevin
spec:
selector:
app: unaryproxy
ports:
- name: unaryproxy-port
port: 3456
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: unaryproxy-deployment
namespace: kevin
labels:
app: unaryproxy
spec:
replicas: 3
selector:
matchLabels:
app: unaryproxy
template:
metadata:
labels:
app: unaryproxy
spec:
containers:
- name: unaryproxy
image: registry-vpc.cn-hangzhou.aliyuncs.com/xapp/unaryproxy:v1
imagePullPolicy: Always
ports:
- containerPort: 3456
volumeMounts:
- name: timezone
mountPath: /etc/localtime
imagePullSecrets:
- name: aliyun
volumes:
- name: timezone
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai