I had some free time this weekend and I've spent some of it trying to learn Go since mlmym seems to be unmaintained and I'd like to try to fix some issues in it. I ran into a stumbling block that took a while to solve and which I had trouble finding relevant search results for. I've got it solved now, but felt like writing this up in case it helps anyone else out.
When running most go commands I tried (e.g. go mod init example/hello or go run hello.go or even something as seemingly innocuous as go doc cmd/compile when a go.mod file exists) the command would hang for a rather long time. In most cases, that was about 20~30 seconds, but in one case -- trying to get it to output the docs about the compile tool -- it took 1 minute and 15 seconds! This was on a relatively fresh Linux Mint install on old, but fairly decent hardware using golang-1.23 (installed from apt).
After the long wait, it would print out go: RLock go.mod: no locks available -- and might or might not do any
Putz travei nos estudos de @golang simplesmente não está funcionando, mas tb não dá erro ahahah responde qq endpoint da minha API com o mesmo, mesmo que seja um endpoint que não existe ele retorna sempre o mesmo valor, no qual deveria, já que não existe, ser um 404. Não sei o que estou fazendo de errado, mas tá foda hahahah Quebrando a cabeça aqui.
A great many PlayStation 2 games were coded in C++, and there are homebrew SDKs that let you work in C. However, precious little software for the platform was ever created in Golang. [Ricardo] deci…
Found myself trying to debug an issue with memory not being garbage collected in a program. It turns out go comes with a tool that shows you the different memory allocations and resource hogs between different goroutines. Super useful so far from what I've found on some basic debugging, but still trying to understand how the flamegraph, the visualizations when writing to a png, and some other utilities in there work.
Overall was happy to learn that there was included tooling for that purpose within go itself.
Simple RBAC in Go. Contribute to AsqewLabs/rbacteria development by creating an account on GitHub.
Link Actions
It appears to pass all tests, but I'm not sure if my test writing skills are necessarily that great, I semi-followed the learn go with tests eBook. I appreciate any feedback, and if this isn't an appropriate post for this community just let me know and I'll remove.
Thanks!!
*** Update ***
Updated the repository to be a bit more discriptive of what the library is for and added in a small example project of it in action.
How to use Enums in Golang, Exploring ways of creating Enums using itoa identifier and struct tags
Link Actions
Background
Imagine you’re building a Todo application using Go. Each task in your application has a status associated with it, indicating whether it’s “completed”, “archived” or “deleted”.
As a developer, you want to ensure that only valid status values are accepted when creating or updating tasks via your API endpoints. Additionally, you want to provide clear error messages to users if they attempt to set an invalid status apart from the valid ones.
Of course, you will say enums, right?
But the bad news is Go doesn’t provide enums and the good news is we can still implement it.
In this blog, we’ll explore how to effectively manage enums in Golang, including validation techniques to ensure data integrity and reliability.
Whether you are a beginner or an experienced developer, this guide aims to demystify enums and empower you to leverage their power in your Go projects.
What is Enum?
Enum is a short form of enumeration, which represents a distinct set
I have a situation where generics would be useful: a server (that I do not control or influence) with many API endpoints that each returns very similar json. There's an envelope with common attributes and then an embedded named substructure (the name differs in the return value of each call) of a different type.
Without generics, you could do something like:
undefined
type Base struct {
// common fields
}
type A {
Base
A struct {
// subtype fields
}
}
type B {
Base
B struct {
// subtype fields
}
}
but then you'd need to either duplicate a bunch of API calling and unmarshalling code, or consolidate it and do a bunch of type casting and checking.
Generics to the rescue: subtypes become specific types for a general type:
undefined
type Base[T any] {
// common fields
Subfield T
}
type A struct {
// subtype fields
}
type B struct {
// subtype fields
}
It even looks cleaner! Ah, but the rub is that the marshaled field name Subfield is the sa