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"
|
|
|
|
|
|
|
|
grpcAPI "git.loafle.net/overflow/overflow_api_server/golang"
|
|
|
|
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
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-08-30 03:21:59 +00:00
|
|
|
return grpc.Dial("192.168.1.103:13234", 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)
|
|
|
|
|
|
|
|
s.Route("POST", "/account/signin", member.SignIn)
|
|
|
|
s.Route("POST", "/account/signup", member.SignUp)
|
|
|
|
s.Route("POST", "/account/forgot_password", member.ForgotPassword)
|
2017-08-30 06:48:04 +00:00
|
|
|
s.Route("POST", "/account/reset_password", member.ResetPassword)
|
2017-08-30 03:21:59 +00:00
|
|
|
s.Route("GET", "/account/check_email", member.CheckEmail)
|
2017-08-23 09:19:21 +00:00
|
|
|
|
|
|
|
fasthttp.ListenAndServe(":19080", s.Handler)
|
|
|
|
}
|