fusen-gateway/server/main.go
2023-11-02 18:40:22 +08:00

45 lines
913 B
Go

package main
import (
"context"
"fusen-gateway/gen/go/service"
"fusen-gateway/proto/goutils"
"fusen-gateway/server/config"
"fusen-gateway/server/logic"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func main() {
fusen := goutils.NewFusen[config.Config]()
fusen.StartNacos(nil)
service.AutoGrpcInit(fusen)
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
mux := runtime.NewServeMux(
runtime.WithForwardResponseOption(logic.ResponseHeaderMatcher),
runtime.WithMarshalerOption("*", &logic.EmptyMarshaler{}),
)
opts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
err := logic.AutoRegisterHandler(ctx, mux, opts...)
if err != nil {
panic(err)
}
err = http.ListenAndServe(":9090", mux)
if err != nil {
panic(err)
}
}