Browse Source

ENV requires config fields be exported

master
David Haukeness 5 years ago
parent
commit
3f8b97baba
No known key found for this signature in database
GPG Key ID: 54F2372DDB7F9462
  1. 8
      main.go

8
main.go

@ -25,7 +25,7 @@ type bot struct {
// fields must be exported for package env (reflect) to work // fields must be exported for package env (reflect) to work
type botConfig struct { type botConfig struct {
Debug bool `env:"BOT_DEBUG" envDefault:"false"` Debug bool `env:"BOT_DEBUG" envDefault:"false"`
logConvIDStr string `env:"BOT_LOG_CONVID" envDefault:""` LogConvIDStr string `env:"BOT_LOG_CONVID" envDefault:""`
} }
// hold reply information when needed // hold reply information when needed
@ -38,7 +38,7 @@ type botReply struct {
func (b *bot) debug(s string, a ...interface{}) { func (b *bot) debug(s string, a ...interface{}) {
if b.config.Debug { if b.config.Debug {
log.Printf(s, a...) log.Printf(s, a...)
if b.config.logConvIDStr != "" { if b.config.LogConvIDStr != "" {
b.logToChat(s, a...) b.logToChat(s, a...)
} }
} }
@ -47,9 +47,9 @@ func (b *bot) debug(s string, a ...interface{}) {
// logToChat will send this message to the keybase chat configured in b.logConv // logToChat will send this message to the keybase chat configured in b.logConv
func (b *bot) logToChat(s string, a ...interface{}) { func (b *bot) logToChat(s string, a ...interface{}) {
// if the ConvIdStr isn't blank try to log // if the ConvIdStr isn't blank try to log
if b.config.logConvIDStr != "" { if b.config.LogConvIDStr != "" {
// if you can't send the message, log the error to stdout // if you can't send the message, log the error to stdout
if _, err := b.k.SendMessageByConvID(chat1.ConvIDStr(b.config.logConvIDStr), s, a...); err != nil { if _, err := b.k.SendMessageByConvID(chat1.ConvIDStr(b.config.LogConvIDStr), s, a...); err != nil {
log.Printf("Unable to log to keybase chat: %s", err) log.Printf("Unable to log to keybase chat: %s", err)
} }
} else { } else {

Loading…
Cancel
Save