talent/setup.go

65 lines
1.3 KiB
Go
Raw Normal View History

2021-12-30 09:16:20 +00:00
package main
import (
"fmt"
"os"
"strings"
"github.com/fatih/color"
2022-01-03 05:06:26 +00:00
"github.com/line/line-bot-sdk-go/v7/linebot"
2021-12-30 09:16:20 +00:00
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func setupLog() {
// log.Logger = log.With().Caller().Logger()
2021-12-30 13:39:00 +00:00
if flagDev {
zerolog.SetGlobalLevel(-1)
log.Logger = log.Output(zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: "2006/01/02 15:04:05",
FormatCaller: func(i interface{}) string {
var c string
if cc, ok := i.(string); ok {
c = cc
}
if len(c) > 0 {
// shorten caller to mod/file:line
segs := strings.Split(c, ":")
file := segs[len(segs)-2]
short := file
ptr := 0
for i := len(file) - 1; i > 0; i-- {
if file[i] == '/' {
if ptr == 0 {
short = file[i+1:]
ptr = i
} else {
short = fmt.Sprintf("%v/%v", file[i+1:ptr], short)
break
}
}
if file[i] == '@' {
2021-12-30 09:16:20 +00:00
ptr = i
}
}
2021-12-30 13:39:00 +00:00
return color.GreenString("%v:%v >", short, segs[len(segs)-1])
2021-12-30 09:16:20 +00:00
}
2021-12-30 13:39:00 +00:00
return c
},
})
}
2021-12-30 09:16:20 +00:00
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
zerolog.DurationFieldInteger = true
2021-12-30 13:39:00 +00:00
}
2022-01-03 05:06:26 +00:00
var bot *linebot.Client
func setupLine() {
var err error
bot, err = linebot.New(LINE_SECRET, LINE_TOKEN)
if err != nil {
panic(err)
2021-12-30 13:39:00 +00:00
}
2021-12-30 09:16:20 +00:00
}