fusen-gateway/server/main.go
2023-11-06 11:58:57 +08:00

46 lines
914 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(":9900", mux)
if err != nil {
panic(err)
}
}