talent/main.go

84 lines
2.2 KiB
Go
Raw Normal View History

2021-12-30 09:16:20 +00:00
package main
import (
2022-01-03 10:28:00 +00:00
"encoding/base64"
2021-12-30 09:16:20 +00:00
"flag"
2022-01-03 10:28:00 +00:00
"fmt"
2021-12-30 13:39:00 +00:00
"time"
2021-12-30 09:16:20 +00:00
"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
2022-01-03 10:28:00 +00:00
IBM_INSTANCE string
IBM_ASSISTANT string
IBM_API string
2021-12-30 09:16:20 +00:00
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")
2022-01-03 10:28:00 +00:00
flag.StringVar(&IBM_INSTANCE, "ibm-instance", "d9329221-40fb-4911-ba9f-69098349b8ab", "watson instance id")
flag.StringVar(&IBM_ASSISTANT, "ibm-assistant", "13cb9242-722a-4644-ba9b-7a761ffe807e", "watson assistant id")
flag.StringVar(&IBM_API, "ibm-api", "tLHR-Fhob0UideN1HUQdQ5grtl338X_VrrT31yy8FbKB", "watson api token")
2021-12-30 09:16:20 +00:00
}
func main() {
2021-12-30 13:39:00 +00:00
tz, err := time.LoadLocation("Asia/Taipei")
if err == nil {
time.Local = tz
}
2021-12-30 09:16:20 +00:00
flag.Parse()
setupLog()
setupServer()
connectToDB()
migrateDB()
setupLine()
2022-01-03 10:28:00 +00:00
IBM_API = fmt.Sprintf("Basic %v", base64.URLEncoding.EncodeToString([]byte(fmt.Sprintf("apikey:%v", IBM_API))))
2021-12-30 09:16:20 +00:00
// setup route
server.GET("/", func(c *gin.Context) { OK(c, "ok") })
2022-01-03 05:06:26 +00:00
// setup api
api := server.Group("api")
api.POST("/email", ApiUpdateEmail)
api.POST("/attach/:oid", ApiPostReceipt)
2021-12-30 09:16:20 +00:00
// 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)
}
}