overflow_server_app/main.go
2017-08-30 14:18:26 +09:00

57 lines
1.4 KiB
Go

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{
InitCapacity: 2,
MaxCapacity: 4,
Dial: func() (*grpc.ClientConn, error) {
return grpc.Dial("192.168.1.103:13234", 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("GET", "/account/check_email", member.CheckEmail)
fasthttp.ListenAndServe(":19080", s.Handler)
}