Here are some random notes about working with Buffalo (may it rest in peace).
Cleaning Up Assets In Buffalo Buffalo doesn’t clean up old versions of bundled JavaScript files. This means that the public/asset directory can grow to gigabytes in size, eventually reaching the point where Go will simply refuse to embed that much data.
The tell-tail sign is this error message when you try to run the application:
too much data in section SDWARFSECT (over 2e+09 bytes) If you see that, deleting public/assets should solve your problem.
Some random notes about the Go language.
Commas in Expression Case Statements The use of comma in case statements work for expression:
x := 2 switch { case x == 1, x == 2: fmt.Println("x < 3") default: fmt.Println("x >= 3") } If x is 1 or 2, the x < 3 will be printed out.
Lookups On A Nil Map You can do lookups on a nil map:
var xs map[string]string = nil x, hasX := xs["hello"] The result will simply be the zero value of the particular type.
I spent the better half of last week trying to build a MacOS .app bundle for one of my Go projects. I want to eventually put this online for others to download, so it was time to work out how to go from a simple binary to a .app bundle.
I want something that is repeatable, automated, and could be done within a GitHub Action, and because this was a Go project, doing this from Xcode was out of the question.
This blog was once a static website generated using Hugo. Like most other static website generators, Hugo provides a lot of features out of the box, one of them being the generation of RSS feeds. I wanted to add a link to an RSS feed of the blog posts to the nav-bar. After trying the /index.xml, I noticed that it included entries for the static pages that are not themselves posts, like the About page.
The errors.New() function in emperror.dev/errors package includes context information, like stack traces. This means that if you were to use this for sentinel error types, i.e. error types like EOL, you’ll be including unnecessary stack information. This is especially useless when these are defined as global variables:
var ErrThing = errors.New("thing happened, but that's OK") Instead, use the errors.Sentinal type.
var ErrThing = errors.Sentinal("thing happened, but that's OK") Dave Cheney discusses why this works.
To get the current colour scheme from the CLI, use the following command:
defaults read -g AppleInterfaceStyle If MacOS is in dark mode, this will print Dark. But if MacOS is in light mode, this key won’t be set at all, and the command will print return an error of the form:
2022-10-04 09:15:18.058 defaults[35844:466643] The domain/default pair of (kCFPreferencesAnyApplication, AppleInterfaceStyle) does not exist As such, in order to confirm that the colour scheme is light, you’ll need to parse for this error.
It looks like it’s possible to replace the items of a subscription while it’s in progress. This can be useful for upgrades, etc. The general technique is as follows:
Take the existing subscription items. Compare with the desired subscription items based of the price ID: If the subscription item is new, create a new subscription item with quantity and price (and whatever else you need). If the subscription item already exists, then make note of the subscription item ID and update details as to what you need, like quantity If the subscription item should be deleted, set the deleted flag to true.
How to determine whether to create a new product for something, or a new price for an existing product for something?
It looks like the way to do so is determine whether what your giving the customer will be different. If it would be, it probably should be a new product. If it’s not, it probably should be a new price of an existing product.
Example would be monthly vs. yearly prices for a 10 GB cloud storage.
Using go:generate to run tools over your Go application is super useful, but how can you know you’ve got the tool installed? Simply having something like:
//go:generate mockery --name=Provider --case=snake --with-expecter would only work if you’ve already got mockery installed.
If the tool is a Go application in a public repository, not a problem. Simply run go install and it’s now on your dev machine:
$ go install github.com/vektra/mockery/v2@latest $ go generate .