1
0

🎨 Little format of the code in NewWebhookChannel helper

This commit is contained in:
Maxim Lebedev 2017-11-24 17:46:47 +05:00
parent 14df773abd
commit f81edf1de7
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F

View File

@ -62,37 +62,48 @@ func (bot *Bot) NewWebhookChannel(
channel := make(chan Update, params.MaxConnections)
go func() {
var err error
if params.Certificate != nil {
if certFile != "" && keyFile != "" {
log.Ln("Creating TLS router...")
err = http.ListenAndServeTLS(
serve,
certFile,
keyFile,
func(ctx *http.RequestCtx) {
if strings.HasPrefix(string(ctx.Path()), listen) {
var update Update
err = json.Unmarshal(ctx.Request.Body(), &update)
if err != nil {
return
}
channel <- update
if !strings.HasPrefix(string(ctx.Path()), listen) {
log.Ln("Unsupported request path:", string(ctx.Path()))
return
}
log.Ln("Catched supported request path:", string(ctx.Path()))
var update Update
err = json.Unmarshal(ctx.Request.Body(), &update)
if err != nil {
log.Ln(err.Error())
return
}
channel <- update
},
)
} else {
log.Ln("Creating simple router...")
err = http.ListenAndServe(
serve,
func(ctx *http.RequestCtx) {
if strings.HasPrefix(string(ctx.Path()), listen) {
var update Update
err = json.Unmarshal(ctx.Request.Body(), &update)
if err != nil {
return
}
channel <- update
if !strings.HasPrefix(string(ctx.Path()), listen) {
log.Ln("Unsupported request path:", string(ctx.Path()))
return
}
log.Ln("Catched supported request path:", string(ctx.Path()))
var update Update
err = json.Unmarshal(ctx.Request.Body(), &update)
if err != nil {
log.Ln(err.Error())
return
}
channel <- update
},
)
}