65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/fatih/color"
|
||
|
"github.com/line/line-bot-sdk-go/v7/linebot"
|
||
|
"github.com/rs/zerolog"
|
||
|
"github.com/rs/zerolog/log"
|
||
|
)
|
||
|
|
||
|
func setupLog() {
|
||
|
// log.Logger = log.With().Caller().Logger()
|
||
|
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] == '@' {
|
||
|
ptr = i
|
||
|
}
|
||
|
}
|
||
|
return color.GreenString("%v:%v >", short, segs[len(segs)-1])
|
||
|
}
|
||
|
return c
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||
|
zerolog.DurationFieldInteger = true
|
||
|
}
|
||
|
|
||
|
var bot *linebot.Client
|
||
|
|
||
|
func setupLine() {
|
||
|
var err error
|
||
|
bot, err = linebot.New(LINE_SECRET, LINE_TOKEN)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|