fusen-gateway/server/main.go

49 lines
944 B
Go
Raw Normal View History

2023-11-02 10:40:22 +00:00
package main
import (
"context"
2023-11-07 03:16:29 +00:00
"fusen-basic/env"
2023-11-02 10:40:22 +00:00
"fusen-gateway/gen/go/service"
2023-11-07 03:16:29 +00:00
2023-11-02 10:40:22 +00:00
"fusen-gateway/server/config"
"fusen-gateway/server/logic"
2023-11-03 05:13:28 +00:00
2023-11-02 10:40:22 +00:00
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func main() {
2023-11-07 03:16:29 +00:00
fusen := env.NewFusen[config.Config]()
2023-11-02 10:40:22 +00:00
fusen.StartNacos(nil)
service.AutoGrpcInit(fusen)
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
mux := runtime.NewServeMux(
2023-11-16 08:24:52 +00:00
runtime.WithMetadata(logic.PassMetadata),
2023-11-02 10:40:22 +00:00
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)
}
2023-11-06 03:58:57 +00:00
err = http.ListenAndServe(":9900", mux)
2023-11-02 10:40:22 +00:00
if err != nil {
panic(err)
}
}