overflow_server_app/main.go

75 lines
2.1 KiB
Go
Raw Normal View History

2017-08-23 09:19:21 +00:00
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"
2017-08-31 10:23:38 +00:00
"git.loafle.net/commons_go/cors_fasthttp"
2017-08-23 09:19:21 +00:00
grpcAPI "git.loafle.net/overflow/overflow_api_server/golang"
"github.com/valyala/fasthttp"
"google.golang.org/grpc"
2017-08-31 10:23:38 +00:00
2017-08-23 09:19:21 +00:00
)
func main() {
2017-08-31 10:23:38 +00:00
ctx := context.Background()
c := cors_fasthttp.AllowAll(ctx)
2017-08-23 09:19:21 +00:00
s := server.New()
grpcPool, err := backend.NewPool(backend.Options{
2017-08-23 09:47:15 +00:00
InitCapacity: 2,
MaxCapacity: 4,
2017-08-23 09:19:21 +00:00
Dial: func() (*grpc.ClientConn, error) {
2017-09-05 04:03:24 +00:00
return grpc.Dial("192.168.1.103:50006", grpc.WithInsecure())
2017-08-23 09:19:21 +00:00
},
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)
2017-08-31 10:23:38 +00:00
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)
2017-08-31 06:37:28 +00:00
2017-08-23 09:19:21 +00:00
2017-08-31 10:23:38 +00:00
fasthttp.ListenAndServe(":19080", c.Handler(s.Handler))
2017-08-23 09:19:21 +00:00
}
2017-08-31 10:23:38 +00:00
//
//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)
// })
//}