74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"net"
|
||
|
"net/http"
|
||
|
"os"
|
||
|
"os/signal"
|
||
|
"syscall"
|
||
|
|
||
|
"github.com/go-kit/kit/log"
|
||
|
"github.com/gorilla/handlers"
|
||
|
"google.golang.org/grpc"
|
||
|
|
||
|
session_pb "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session"
|
||
|
session_endpoints "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/endpoints"
|
||
|
session_grpctransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/grpc"
|
||
|
session_httptransport "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/gen/transports/http"
|
||
|
sessionsvc "github.com/moul/protoc-gen-gotemplate/examples/go-kit/services/session/svc"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
mux := http.NewServeMux()
|
||
|
ctx := context.Background()
|
||
|
errc := make(chan error)
|
||
|
s := grpc.NewServer()
|
||
|
var logger log.Logger
|
||
|
{
|
||
|
logger = log.NewLogfmtLogger(os.Stdout)
|
||
|
logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC)
|
||
|
logger = log.NewContext(logger).With("caller", log.DefaultCaller)
|
||
|
}
|
||
|
|
||
|
// initialize services
|
||
|
{
|
||
|
svc := sessionsvc.New()
|
||
|
endpoints := session_endpoints.MakeEndpoints(svc)
|
||
|
srv := session_grpctransport.MakeGRPCServer(ctx, endpoints)
|
||
|
session_pb.RegisterSessionServiceServer(s, srv)
|
||
|
session_httptransport.RegisterHandlers(ctx, svc, mux, endpoints)
|
||
|
}
|
||
|
{
|
||
|
//svc := sprintsvc.New()
|
||
|
|
||
|
}
|
||
|
|
||
|
// start servers
|
||
|
go func() {
|
||
|
c := make(chan os.Signal, 1)
|
||
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
||
|
errc <- fmt.Errorf("%s", <-c)
|
||
|
}()
|
||
|
|
||
|
go func() {
|
||
|
logger := log.NewContext(logger).With("transport", "HTTP")
|
||
|
logger.Log("addr", ":8000")
|
||
|
errc <- http.ListenAndServe(":8000", handlers.LoggingHandler(os.Stderr, mux))
|
||
|
}()
|
||
|
|
||
|
go func() {
|
||
|
logger := log.NewContext(logger).With("transport", "gRPC")
|
||
|
ln, err := net.Listen("tcp", ":9000")
|
||
|
if err != nil {
|
||
|
errc <- err
|
||
|
return
|
||
|
}
|
||
|
logger.Log("addr", ":9000")
|
||
|
errc <- s.Serve(ln)
|
||
|
}()
|
||
|
|
||
|
logger.Log("exit", <-errc)
|
||
|
}
|