2017-08-23 09:19:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2017-09-05 06:37:33 +00:00
|
|
|
"encoding/json"
|
|
|
|
"log"
|
2017-08-23 09:19:21 +00:00
|
|
|
|
2017-09-05 06:37:33 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"git.loafle.net/commons_go/config"
|
|
|
|
"git.loafle.net/commons_go/cors_fasthttp"
|
|
|
|
"git.loafle.net/commons_go/logging"
|
|
|
|
"git.loafle.net/overflow/overflow_server_app/grpc"
|
2017-08-23 09:19:21 +00:00
|
|
|
"git.loafle.net/overflow/overflow_server_app/module/member"
|
|
|
|
"git.loafle.net/overflow/overflow_server_app/server"
|
|
|
|
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
)
|
|
|
|
|
2017-09-05 06:37:33 +00:00
|
|
|
var logger *zap.Logger
|
2017-08-31 10:23:38 +00:00
|
|
|
|
2017-09-05 06:37:33 +00:00
|
|
|
func main() {
|
|
|
|
loadConfig()
|
|
|
|
ctx := newContext()
|
|
|
|
defer logger.Sync()
|
2017-08-23 09:19:21 +00:00
|
|
|
|
2017-09-05 06:37:33 +00:00
|
|
|
c := cors_fasthttp.AllowAll(ctx)
|
|
|
|
grpc.InitializePool(ctx)
|
2017-08-23 09:19:21 +00:00
|
|
|
|
2017-09-05 06:37:33 +00:00
|
|
|
s := server.New(ctx)
|
2017-08-23 09:19:21 +00:00
|
|
|
|
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-31 10:23:38 +00:00
|
|
|
fasthttp.ListenAndServe(":19080", c.Handler(s.Handler))
|
2017-08-23 09:19:21 +00:00
|
|
|
}
|
2017-09-05 06:37:33 +00:00
|
|
|
|
|
|
|
func loadConfig() {
|
|
|
|
config.SetConfigName("config")
|
|
|
|
config.AddConfigPath(".")
|
|
|
|
err := config.ReadInConfig()
|
|
|
|
if nil != err {
|
|
|
|
log.Fatalf("config error: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newContext() context.Context {
|
|
|
|
var err error
|
|
|
|
ctx := context.Background()
|
|
|
|
logConfig := config.Sub("logging")
|
|
|
|
|
|
|
|
buf, err := logConfig.Marshal("json")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
var cfg zap.Config
|
|
|
|
if err = json.Unmarshal(buf, &cfg); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
logger, err = cfg.Build()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = logging.NewContext(ctx, logger)
|
|
|
|
|
|
|
|
return ctx
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
// })
|
2017-09-05 06:37:33 +00:00
|
|
|
//}
|