Welcome to the Anti-Spam Bot project! This bot is designed to monitor and manage spam activities, ensuring smooth and uninterrupted conversations.
https://github.com/evgensr/anti-spam
Welcome to the Anti-Spam Bot project! This bot is designed to monitor and manage spam activities, ensuring smooth and uninterrupted conversations.
https://github.com/evgensr/anti-spam
Fixing For Loops in Go 1.22
https://go.dev/blog/loopvar-preview
David Chase и Russ Cox в официальном блоге Go рассказывают про проблему LoopVar (переменной цикла) и приводят конкретные примеры, в том числе из реального кейса проекта — Lets Encrypt.
Затем рассказывают, как именно эта проблема решается. Если кратко:
> change for loops to make these variables have per-iteration scope instead of per-loop scope
Как вы помните, эта фича уже есть в Go v1.21, но её нужно включить:
GOEXPERIMENT=loopvar go test
А в версии 1.22 она уже будет работать по-умолчанию
package main
import "github.com/gin-gonic/gin"
func RequestLogger() gin.HandlerFunc {
return func(c *gin.Context) {
t := time.Now()
c.Next()
latency := time.Since(t)
fmt.Printf("%s %s %s %s\n",
c.Request.Method,
c.Request.RequestURI,
c.Request.Proto,
latency,
)
}
}
func ResponseLogger() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("X-Content-Type-Options", "nosniff")
c.Next()
fmt.Printf("%d %s %s\n",
c.Writer.Status(),
c.Request.Method,
c.Request.RequestURI,
)
}
}
func main() {
r := gin.Default()
// Add logging middleware
r.Use(RequestLogger())
r.Use(ResponseLogger())
r.GET("/", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "Hello, World!",
})
})
r.Run() // listen and serve on 0.0.0.0:8080
}
func forex() string {
client := &http.Client{
Timeout: 10 * time.Second,
}
req, err := http.NewRequest("GET", "https://www.investing.com/currencies/usd-rub", nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537")
res, err := client.Do(req)
if err != nil {
log.Println(err)
}
defer res.Body.Close()
if res.StatusCode != 200 {
log.Printf("status code error: %d %s", res.StatusCode, res.Status)
}
// Load the HTML document
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
log.Println(err)
}
var price string
doc.Find("span[data-test='instrument-price-last']").Each(func(index int, item *goquery.Selection) {
price = item.Text()
fmt.Println(price)
})
return price
}
services:
web:
build: .
ports:
- "80:80"
depends_on:
db:
condition: service_healthy
restart: always
db:
image: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5