feat: initial commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user