add README.md
This commit is contained in:
parent
288f880cdd
commit
79a6ffda84
|
@ -3,3 +3,6 @@ api/*.proto
|
|||
Makefile
|
||||
|
||||
cmd/**
|
||||
internal/**
|
||||
|
||||
README.md
|
||||
|
|
14
README.md
14
README.md
|
@ -1,3 +1,15 @@
|
|||
# template
|
||||
|
||||
Шалон для Go сервисов
|
||||
Шалон для Go сервисов
|
||||
|
||||
Генерация контракта
|
||||
|
||||
```shell
|
||||
make generate
|
||||
```
|
||||
|
||||
Запуск
|
||||
|
||||
```shell
|
||||
make run
|
||||
```
|
||||
|
|
|
@ -1,7 +1,56 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"${REPO_NAME_SNAKE}/internal/app"
|
||||
proto "${REPO_NAME_SNAKE}/proto"
|
||||
"context"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, World!")
|
||||
// Create a listener on TCP port
|
||||
lis, err := net.Listen("tcp", ":8080")
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to listen:", err)
|
||||
}
|
||||
|
||||
// Create a gRPC server object
|
||||
s := grpc.NewServer()
|
||||
// Attach the Greeter service to the server
|
||||
proto.Register${REPO_NAME_PASCAL}Server(s, app.NewServer())
|
||||
// Serve gRPC server
|
||||
log.Println("Serving gRPC on 0.0.0.0:8080")
|
||||
go func() {
|
||||
log.Fatalln(s.Serve(lis))
|
||||
}()
|
||||
|
||||
// Create a client connection to the gRPC server we just started
|
||||
// This is where the gRPC-Gateway proxies the requests
|
||||
conn, err := grpc.NewClient(
|
||||
"0.0.0.0:8080",
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to dial server:", err)
|
||||
}
|
||||
|
||||
gwmux := runtime.NewServeMux()
|
||||
// Register Greeter
|
||||
err = proto.Register${REPO_NAME_PASCAL}Handler(context.Background(), gwmux, conn)
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to register gateway:", err)
|
||||
}
|
||||
|
||||
gwServer := &http.Server{
|
||||
Addr: ":8090",
|
||||
Handler: gwmux,
|
||||
}
|
||||
|
||||
log.Println("Serving gRPC-Gateway on http://0.0.0.0:8090")
|
||||
log.Fatalln(gwServer.ListenAndServe())
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
module cake_crm
|
||||
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/go-pkgz/routegroup v1.1.1
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8
|
||||
google.golang.org/grpc v1.64.0
|
||||
google.golang.org/protobuf v1.34.1
|
||||
)
|
||||
|
||||
require (
|
||||
golang.org/x/net v0.23.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 // indirect
|
||||
)
|
|
@ -0,0 +1,18 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
proto "${REPO_NAME_SNAKE}/proto"
|
||||
"context"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
proto.UnimplementedCRMServer
|
||||
}
|
||||
|
||||
func NewServer() *Server {
|
||||
return &Server{}
|
||||
}
|
||||
|
||||
func (s *Server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, error) {
|
||||
return &proto.PingRsp{}, nil
|
||||
}
|
Loading…
Reference in New Issue