Golang – extract links using regex

Golang – extract links using regex I need to get all links from text which are in specific domain example.de using Regex in Go Below are all possible links that should be extracted: https://example.de https://example.de/ https://example.de/home https://example.de/home/ https://example.de/home some text that should not be extracted https://abc.example.de https://abc.example.de/ https://abc.example.de/home https://abc.example.de/home https://abc.example.de/home some text that should not… Read More Golang – extract links using regex

continue the execution of a function after handled panic

I’m trying to make a task scheduler that does tasks in the given interval and also can handle an occurring panic. My question is how can I continue executing the function after handling the panic. func scheduleTask(task func() error, interval time.Duration, timeout time.Duration) { //add waitgroup and mutex var wg sync.WaitGroup var mtx sync.Mutex var… Read More continue the execution of a function after handled panic

GoLang – bbolt – invalid memory address or nil pointer dereference

I am trying to use file database bbolt as a key/value storage. Below is my code package handler import ( "encoding/json" "log" "net/http" "os" "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt" yml "gopkg.in/yaml.v3" ) type urlDB struct { db *bbolt.DB } func (u urlDB) ensureDB() { u.db, _ = bolt.Open("url.db", 0600, nil) } func MapHandler(pathsToURLs map[string]string, fallback http.Handler) http.HandlerFunc… Read More GoLang – bbolt – invalid memory address or nil pointer dereference

Creating a single json object with several nested objects from a map in Go

Apologies if my question was worded poorly. I’m new to Go and trying to format some data into JSON by using marshaling. My function looks like: func writeJSON(w http.ResponseWriter, rep similarity.Similarity, keys []string) { for _, sub := range rep.Submissions { var jsonMap = make(map[string]interface{}) vals := makeRow(sub) for i := range vals { jsonMap[keys[i]]… Read More Creating a single json object with several nested objects from a map in Go

Not getting any output even if there is no race conditions

I am trying to create producer-consumer message queue system in Golang using buffered channel. Here is my implementation. package main import "fmt" type MessageQueue struct { storage chan int count int } var done = make(chan bool) func NewMessageQueue(count int) *MessageQueue { ret := &MessageQueue{ count: count, storage: make(chan int, count), } return ret }… Read More Not getting any output even if there is no race conditions

Why doesn't `go run` leave behind the produced binary instead of deleting it?

From what I understand, go run creates a binary, runs it, and then deletes it. Why delete it? Doesn’t it mean that when running go run again, everything will need to be done again even if nothing has changed? For the record, cargo run (for Rust) doesn’t delete the binary. What was the reasoning behind… Read More Why doesn't `go run` leave behind the produced binary instead of deleting it?