overflow_server_app/main.go

67 lines
1.9 KiB
Go
Raw Permalink Normal View History

2017-08-23 09:19:21 +00:00
package main
import (
2017-09-08 06:05:46 +00:00
"flag"
2017-08-23 09:19:21 +00:00
2017-11-23 08:06:44 +00:00
cc "git.loafle.net/commons_go/config"
2017-09-05 06:37:33 +00:00
"git.loafle.net/commons_go/cors_fasthttp"
"git.loafle.net/commons_go/logging"
2018-03-21 11:42:06 +00:00
oocc "git.loafle.net/overflow/overflow_commons_go/config"
2017-11-23 08:06:44 +00:00
"git.loafle.net/overflow/overflow_server_app/config"
"git.loafle.net/overflow/overflow_server_app/external"
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"
)
2018-03-21 11:42:06 +00:00
var (
configDir *string
logConfigPath *string
)
2017-09-08 06:05:46 +00:00
2018-03-21 11:42:06 +00:00
func init() {
configDir = oocc.FlagConfigDir("./")
logConfigPath = oocc.FlagLogConfigFilePath("")
2017-09-08 06:05:46 +00:00
flag.Parse()
2018-03-21 11:42:06 +00:00
logging.InitializeLogger(*logConfigPath)
cc.SetConfigPath(*configDir)
if err := cc.Load(&config.Config, oocc.ConfigFileName); nil != err {
logging.Logger().Panic(err)
2017-11-23 08:06:44 +00:00
}
}
2017-08-23 09:19:21 +00:00
2017-11-23 08:06:44 +00:00
func main() {
defer logging.Logger().Sync()
2017-08-23 09:19:21 +00:00
2017-11-23 08:06:44 +00:00
external.ExternalInit()
2017-08-23 09:19:21 +00:00
2017-11-23 08:06:44 +00:00
s := server.New()
2018-03-14 09:45:07 +00:00
s.Route("POST", "/account/signin", member.Signin)
s.Route("POST", "/account/signin_cookie", member.SigninByCookie)
2017-08-31 10:23:38 +00:00
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-11-23 08:06:44 +00:00
c := cors_fasthttp.AllowAll()
fasthttp.ListenAndServe(config.Config.Server.Addr, c.Handler(s.Handler))
2017-09-05 06:37:33 +00:00
2017-11-23 08:06:44 +00:00
external.ExternalDestroy()
2017-09-05 06:37:33 +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)
// })
2017-09-05 06:37:33 +00:00
//}