47 lines
779 B
Go
47 lines
779 B
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"gogrpc/proto"
|
|
"log/slog"
|
|
"net"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
//go:embed proto
|
|
var protoFS embed.FS
|
|
|
|
func startWebServer(abort chan struct{}) {
|
|
fileServer := http.FileServer(http.FS(protoFS))
|
|
|
|
r := gin.Default()
|
|
r.GET("/*filepath", gin.WrapH(fileServer))
|
|
|
|
r.Run()
|
|
|
|
slog.Error("failed to start web server")
|
|
abort <- struct{}{}
|
|
}
|
|
|
|
func startGrpcServer(abort chan struct{}) {
|
|
listener, _ := net.Listen("tcp", ":1337")
|
|
service := grpc.NewServer()
|
|
proto.RegisterServiceServer(service, &Service{})
|
|
service.Serve(listener)
|
|
|
|
slog.Error("failed to start grpc server")
|
|
abort <- struct{}{}
|
|
}
|
|
|
|
func main() {
|
|
abort := make(chan struct{})
|
|
|
|
go startWebServer(abort)
|
|
go startGrpcServer(abort)
|
|
|
|
<-abort
|
|
}
|