The Ebitengine Game Jam is a 2-week event starting on 15 June organised by the Ebitengine community for anyone to showcase the by building games based on a secret theme.
The secret theme this year has been announced, it's: BUILDING 🏗️🍤 (including build, build up, builder, etc.)! Feel free to interpret it figuratively or completely literally, it's up to you, so get creative! For more details and to join in, see:
I'm mostly a backend developer and I'm creating a small web application (less than 50 pages) using html/template (the frontend doesn't require a lot of interactivity either, so html/template suits quite well).
When I started putting everything together I followed the simple code examples I saw out there, where the famous 'data' struct is declared on the fly, everything needed to render the template was shoved in there, and then passed on to the 'Execute' function.
Is that really the best way to do this? As the page gets more sophisticated the code starts looking more and more ugly with an ever bigger 'data' struct.
When dealing with forms, for example, you need to preserve the form data in between posts (if server-side validation is not successful), include validation errors, plus whatever other flags and data is needed to render the rest of the template. Once form validation is successful you need to translate the form data into whatever structs and functions you've implemented for triggering additional business logic and/or persistence logic.
I tried creating explicit structs (like 'UserForm', where I declare all the form fields, and 'UserFormErrors' where I have a set of string fields with errors that may be generated while validating the form). It certainly makes the web handler function cleaner, and declaring all the structs beforehand also make it easier to compare struct field names against the variable names you see referenced on the template. But is this the best way to go? Something tells me I'm missing a simpler way to do this...
First beta release of Godocx is out now. Basic functions has been implemented.
You can
-
Add paragraph, headings with different styles
-
Add picture
-
Add table with different styles
-
Add bullet/number list
-
You can open existing docx and modify or create docx from scratch
There are more functions and elements has yet to be implemented.
i'm going to put together a microservice. For logging i guess i'll just go with slog, but what are the popular choices for metrics and tracing libs these day? Grafana compatibility preferred.
thnx in advance.
I'm just starting with Go, and coming from Python I'm having to twist my brain a little bit to get my grips about OOP here.
I have an User
struct, and a GetUser
function. I'd like to be able to call User.Get
instead of GetUser
, as it feels slightly more orderly. This is what I have right now:
func (User) Get(apiKey string) (user *User, err error) { return GetUser(apiKey) }
And now I can call User{}.Get("123")
.
This works, but is this idiomatic Go, or just a workaround?
This is the stack I use.
It takes the pain out of doing lots of development quickly with a gitops style of development without needing K8, docker and heavy stuff.
Task and Task-UI
I am using Task and Task-ui and runner
Task-UI ONLY works with Docker and I am planning to modify it to work with Runner ( see below ).
There is nothing wrong with Docker, but I find I just dont need it.
Task is where you can build workflows easily.
Is also replaced the GitHub actions, with the GitHub actions being a very simple standard template that just installs Task and then calls Task. So everything that you run locally is the same as what is run on Github Actions. Its DRY, and flexible so you can also run your Task on exotic hardware that Github does not support too.
runner
is able to run many processes on any OS and also can run clusters of process, like when you need 3 of something for clustering. I run it locally and in Production.
It's 100% golang and just needs a ProcFile and a .ENV, so its very simple but also can do what docker and docker-compose can do.
It has a real time GUI, so I can see everything happening on all servers both locally and remotely. You can all the processes running.
It also has a decent waiter, so that you can declare that X has to wait for Y.
It has full supervisions trees, which allows it to do what docker compose does.
I have been using this for 6 months in Production and it's been fast and easy and stable.
package management
Then there is aqua for package management. This is 100% golang and works on All desktops.
It allows me to declare a binary package I need and keep it updated.
has a huge list of packages that is growing all the time.
Deploy
I can then deploy to
Runner can run things on just fine.
You can also deploy this to any cloud, because of the nature of it.
does autoscaling for you, Or you can also write your own custom scheduling for really large and complex things.
I need to deploy at the edge ad so use Cloudflare tunnel to expose it easily. This is free with Cloudflare. At the Edge Runner and aqua work fine without Docker on any desktops and servers.
CI / CD
With all this, its means my Github Actions are all identical for each project. It's really just a GitHub action that installs golang and task and calls Task to build and package my stuff to Aqua ( binaries ) , Docker Registry ( docker images ) that pull in the binaries from the Aqua registry at build time.
Running Aqua Registry on is easy, along with its nice GUI and CLI.
I've written a program which parses a file, and I want to now increase the performance of it. However, it has a lot of logic to it, and I want to find what specific parts of it are the biggest performance hits.
Are there any useful tools or patterns in Go which would help with this? Any experiences doing something similar would also be very good to hear.
In regards to the new 'iterators' coming in Go 1.23, I stumbled upon some blog posts and chatter on social media talking about how this is an unnecessary language change. I was somewhat aware of the proposal and thought the func(func(T)bool) bool
was a bit odd but after seeing this, I started investigating further and contributing to the discussion on
I've always thought channels are the obvious choice for representing iterators (as they represent a stream, queue or sequence of values), naturally I assumed there must be a good reason why the language had to change the spec in order to support iterators (instead of adding compiler optimisations for channels to support this, I've even gone into some detail on how this could be implemented efficiently).
The reaction I've received, however, is bizarre? I've been told it's too late to comment on this, it's already been decided. That channels must not be used for this (technically they can be used as iterators). Instead Go is adding special case functions to the language spec and a special case package iter
just to support the same language semantics as receive-only channels?
I've always considered Go (and the community) to be very cautious about making languages changes, not to add duplicate ways of representing the same thing. Pushing a cohesive and simple design. I'm curious, is it just me feeling like there is a major shift in principles here and is there anybody else who has had a look at this and thought the built-in channels are the obvious answer here?
OK, I've got a basic TView app that creates three items -- on the top is a TextView, and below it, there are two items in a horizontal Flex with a text entry on the left and a submit button on the right... BUT.....
package main import ( "github.com/rivo/tview" ) func main() { app := tview.NewApplication() // Console at the top console := tview.NewTextView() console.SetTitle(" Chicken3000: What's going on at the farm ") console.SetBorder(true) // Input field inputField := tview.NewInputField() inputField.SetLabel(" Enter a command: ") inputField.SetBorder(true) // Button to the right button := tview.NewButton("Submit") // Horizontal flex for the inputField and button flexBottom := tview.NewFlex(). AddItem(inputField, 0, 1, true). AddItem(button, 0, 1, false) // Vertical flex for console and the horizontal flex flex := tview.NewFlex().SetDirection(tview.FlexRow). AddItem(console, 0, 1, false). AddItem(flexBottom, 0, 1, true) if err := app.SetRoot(flex, true).Run(); err != nil { panic(err) } }
The problem is, the text entry and buttons are huge. I want the text entry field to take about about 80% of the line from the left, and a small button on the right. Also, the text entry field should be multi-line if I can. What did I do wrong?
Over the past several months I have been learning how to program in Go by reading articles and blog posts, as well as ebooks and tutorials. This is my attempt at a simple Go CRUD web app. I tried to keep things simple by not using any frameworks and only using one third party dependency.
It seems that many tutorials and books will go from Hello World to something really complicated, with nothing in between. Others would give the routes on the back-end, with no front-end to go along with it. That frustrated me.
Hopefully this helps someone out.
Any comments, advice or tips would be welcome.
I started learning go fairly recently. While reading , I came across two intriguing examples (notice use of pointers):
type path []byte func (p path) ToUpper() { for i, b := range p { if 'a' <= b && b <= 'z' { p[i] = b + 'A' - 'a' } } } func main() { pathName := path("/usr/bin/tso") pathName.ToUpper() fmt.Printf("%s\n", pathName) // /USR/BIN/TSO }
type path []byte func (p *path) TruncateAtFinalSlash() { i := bytes.LastIndex(*p, []byte("/")) if i >= 0 { *p = (*p)[0:i] } } func main() { pathName := path("/usr/bin/tso") // Conversion from string to path. pathName.TruncateAtFinalSlash() fmt.Printf("%s\n", pathName) // /usr/bin }
I am confused about why the former doesn't need to use a pointer receiver, and latter does. If I understood correctly, one modifies the original array, therefore not needing a pointer, and the other one modifies the slice itself (referred as the sliceHeader in the article) ?
Thank you:)
Hey guys, i hope youre doing well
I was looking for good visual content to learn about pointers in golang, and i remembered a youtube video that i once saw about the topic, it was from a asian/half asian girl, but i cant find it anywhere.
She had really good explanations about the topics, and even got cool draws and animations to explain the concepts of pointers etc. Im new to Go, and i dont know if she is known by the go community, but her content was by far the one that most got into my brain, probably because it was really visual.
Do you guys make any idea of who she is? and if yes, is there anywhere else to find her content?
I came from python so using golang was a bit tough for me , but yeah once you get used to it , it's not that hard plus the speed is a lot faster compared to python
Hello fellow gophers.
Maybe I am very stupid, but official doc or Gemini help I can't make it work.
I just want to see test coverage on gitlab
EDIT : Find solution (comment)
I am trying to implement some sort of rate limiter for one of my loops. While researching ways to do it, I came across ticker
. Would love it if someone can review my implementation/pseudo code... I am not sure if I really understand how it works.
Context: I am sending some emails via SES to my users, and I need to stay within the mails/second limit.
Implementation:
ticker := time.NewTicker(100 * time.Millisecond) // 10 mails/second defer ticker.Stop() for _, job := range completed_jobs { // query db for job owner and users "watching" the job, store in a variable recipients for _, recipient := range recipients{ // generate email content from template <-ticker.C // Wait for the ticker go MailClient().Send(message) } }
I am assuming, ticker.Stop() is called when the outer loop completes. Please suggest alternatives if there is a better way to do this. TIA.
I have two Ecoflow devices (River 2 and Delta 2) and it's frustrating that official app doesn't provide history metrics. Also the app doesn't show a lot of metrics which might be interested for end user (like input/output voltage, temperature, etc). That's why I've implemented two libraries:
-
go-ecoflow - to provide some basic API to get metrics from Ecoflow devices (via REST API). Github: . Currently there are two main API: list all devices linked to the account and get all metrics for the device. The REST API provided by Ecoflow is tricky in terms of SIGN header - the logic to calculate it is pretty complex (documentation ). I might implement change Ecoflow settings via REST API in sometime. Currently I don't have any use case for this.
-
go-ecoflow-exporter - Prometheus exporter. It uses the abovementioned library to access the API. The metrics are sent to Prometheus and then rendered in Grafana. Github repository:
Screenshots (not allowed in this sub-reddit) and all instructions are on Github:
The inspiration and Grafana dashboard is taken from this github repository: . It is implemented in Python using MQTT.