package main import ( "context" "git.loafle.net/overflow/overflow_server_app/backend" "git.loafle.net/overflow/overflow_server_app/module/member" "git.loafle.net/overflow/overflow_server_app/server" "git.loafle.net/commons_go/cors_fasthttp" grpcAPI "git.loafle.net/overflow/overflow_api_server/golang" "github.com/valyala/fasthttp" "google.golang.org/grpc" ) func main() { ctx := context.Background() c := cors_fasthttp.AllowAll(ctx) s := server.New() grpcPool, err := backend.NewPool(backend.Options{ InitCapacity: 2, MaxCapacity: 4, Dial: func() (*grpc.ClientConn, error) { return grpc.Dial("192.168.1.103:50006", grpc.WithInsecure()) }, NewClient: func(conn *grpc.ClientConn) (interface{}, error) { return grpcAPI.NewOverflowApiServerClient(conn), nil }, Exec: func(client interface{}, target string, method string, params []string) (string, error) { ctx := context.Background() c := client.(grpcAPI.OverflowApiServerClient) si := &grpcAPI.ServerInput{ Target: target, Method: method, Params: params, } so, err := c.Exec(ctx, si) if nil != err { return "", err } return so.Result, nil }, }) if nil != err { } s.SetContextValue("grpc", grpcPool) s.Route("POST", "/account/signin", member.SignIn) s.Route("POST", "/account/signup", member.SignUp) s.Route("POST", "/account/forgot_password", member.ForgotPassword) s.Route("POST", "/account/reset_password", member.ResetPassword) s.Route("GET", "/account/check_email", member.CheckEmail) fasthttp.ListenAndServe(":19080", c.Handler(s.Handler)) } // //func CORS(next server.RequestHandler) server.RequestHandler { // return server.RequestHandler(func(sctx *server.ServerContext, ctx * fasthttp.RequestCtx) { // // ctx.Response.Header.Set("Access-Control-Allow-Credentials", "true" ) // ctx.Response.Header.Set("Access-Control-Allow-Headers", "authorization") // ctx.Response.Header.Set("Access-Control-Allow-Methods", "HEAD,GET,POST,PUT,DELETE,OPTIONS" ) // ctx.Response.Header.Set("Access-Control-Allow-Origin", "*") // // next(sctx, ctx) // }) //}