talent/main.go

62 lines
1.5 KiB
Go
Raw Normal View History

2021-12-30 09:16:20 +00:00
package main
import (
"flag"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
)
var (
flagAddr string
flagDev bool
DB_HOST string
DB_USER string
DB_PASSWD string
DB_NAME string
DB_PORT int
LINE_SECRET string
LINE_TOKEN string
Version string
Build string
)
func init() {
flag.StringVar(&flagAddr, "addr", "0.0.0.0:8000", "address to listen on.")
flag.BoolVar(&flagDev, "dev", false, "is dev mode")
flag.StringVar(&DB_HOST, "db-host", "postgres.ework.tw", "postgress db host.")
flag.StringVar(&DB_USER, "db-user", "talent", "postgress db user.")
flag.StringVar(&DB_PASSWD, "db-passwd", "show", "postgress db pqssword.")
flag.StringVar(&DB_NAME, "db-name", "talent", "postgress db name.")
flag.IntVar(&DB_PORT, "db-port", 5432, "postgress db port.")
flag.StringVar(&LINE_SECRET, "line-secret", "cf406aa7577569ba2b211bc04f51630e", "line channel secret.")
flag.StringVar(&LINE_TOKEN, "line-token", "IhP4dLM91boFQlRzHa/Iv9el2xXm2X6ByiDuWQXm6ndQL1LA+yA+O8x2OeuJkpSWlf5IE8cwkA+Mca18EjO42Q6vRm0T5cRdTLkO+42SX9HAx2GdJnhWu+S4IplOt38YktfmpodCyk6bXDBJp9YVwgdB04t89/1O/w1cDnyilFU=", "channel access token")
}
func main() {
flag.Parse()
setupLog()
setupServer()
connectToDB()
migrateDB()
setupLine()
// setup route
server.GET("/", func(c *gin.Context) { OK(c, "ok") })
// setup bot webhook
hook := server.Group("bot")
hook.POST("/", webhook)
// start server
log.Info().Msgf("serving on %v", flagAddr)
if err := server.Run(flagAddr); err != nil {
panic(err)
}
}