News for hackers. Stuff that matters.
Re:Go command support for embedded static assets (files) by axaxs on Thursday July 23, 2020 @08:43PM (#23934436)
Can someone explain please the point of embedding bin data into a binary, vs just bundling those assets and opening as a file at runtime?
Re:Go command support for embedded static assets (files) by politician on Thursday July 23, 2020 @10:33PM (#23935104)
Store SQL scripts as embedded resources rather than string constants. When SQL scripts are stored as individual ".sql" files, both version control and syntax highlighting is better.

This works with most editors and doesn't require fancy multi-language syntax highlighting support. When debugging complex scripts that involve many joins or CTEs having good highlighting can prevent a lot of headaches.

Re:Go command support for embedded static assets (files) by mcpherrinm on Thursday July 23, 2020 @09:45PM (#23934823)
Imagine you are shipping a library. Say, one that tells you about timezones.

You want your users to just be able to import that library and use it. The fact that you need a bunch of zone info files should be invisible to them.

Maybe those users are in a sandboxed environment that doesn't allow opening files, or you're in webassembly where files don't exist.

It's much simpler to just bake that data into the library.

Re:Go command support for embedded static assets (files) by DaiPlusPlus on Thursday July 23, 2020 @10:26PM (#23935057)
I’d prefer a library that uses the IANA tzdb directly - so I can download the latest tzdb files for my application and OS without needing to wait for the maintainer of that library to ship an update.
Re:Go command support for embedded static assets (files) by elcomet on Friday July 24, 2020 @03:59AM (#23936900)
You missed the point. This is not about timezones, but about the need that sometimes happen to embed files into a library.

Parent just chose timezones as an example.

Re:Go command support for embedded static assets (files) by malandrew on Friday July 24, 2020 @04:06AM (#23936940)
They used time zones to illustrate a point. Of course it’s generally best to use that file instead for that specific use case. Now imagine some data that isn’t shipped with Linux by default. That’s the point they were trying to make.
Re:Go command support for embedded static assets (files) by jhardy54 on Thursday July 23, 2020 @08:45PM (#23934443)
Convenience. It's easier and more foolproof to give someone one file than it is to give them a directory.
Re:Go command support for embedded static assets (files) by mickaelkerjean on Thursday July 23, 2020 @10:03PM (#23934924)
Yes! I can't count how many people have tried to use my software (https://github.com/mickael-kerjean/filestash), flushing some entire directories with docker volume and creating support tickets and emails as things got broken.

The landscape of tools supposed to solve that problem isn't great. Things are changing way too fast with projects being archived or deprecated with mention to migrate to another solution which after another year is deprecated again. Because of those issue, I've went with go generate which isn't ideal but is at least stable. That proposal would be a game changer and hopefully it will become a reality as Brad is quite a prominent figure in the Golang world.

Re:Go command support for embedded static assets (files) by throwaway29103 on Friday July 24, 2020 @07:58AM (#23938443)
Sorry... what do you mean by "flushing" (thanks)

BTW. Fantastic software, filestash - really really good.

Re:Go command support for embedded static assets (files) by jhardy54 on Friday July 24, 2020 @04:16PM (#23943961)
My guess: deleting.
Re:Go command support for embedded static assets (files) by throwaway29103 on Saturday July 25, 2020 @08:45AM (#23948783)
Thanks, first I thought... it cannot be, because when you delete the container, the named volumes are still there; but I guess that they might have deleted contents using the app itself, without realizing they were sharing the directory...
Re:Go command support for embedded static assets (files) by jhardy54 on Saturday July 25, 2020 @01:36PM (#23950963)
`docker system prune rm -af` ftw
Re:Go command support for embedded static assets (files) by throwaway29103 on Monday July 27, 2020 @11:00AM (#23965711)
Thanks, will this also remove the files in named volumes? I hope it won't! (Will not try :-D)
Re:Go command support for embedded static assets (files) by alain_gilbert on Thursday July 23, 2020 @08:46PM (#23934450)
I personally find it more elegant to distribute a single .exe file which contains all the html/js/css inside it, to customers.

Instead of having a "messy" folder on their computer.

Re:Go command support for embedded static assets (files) by dewey on Friday July 24, 2020 @04:28AM (#23937091)
Sometimes I write tiny services with a web interface that I can just distribute through scp'ing the binary. In this case I can embed the favicon and other tiny files directly into the binary without making the deployment more complicated.
Re:Go command support for embedded static assets (files) by kevin_thibedeau on Thursday July 23, 2020 @10:27PM (#23935064)
You might not have a filesystem.
Re:Go command support for embedded static assets (files) by hombre_fatal on Thursday July 23, 2020 @09:11PM (#23934606)
Consider the reverse question: it's simpler to just ship files in the binary unless you need one of the specific advantages of loose-leaf files (like the user being able to modify them, other processes like Nginx reading them).

If you don't need one of the features of having "moving parts" on the filesystem, then why would you want a dependency on the local filesystem?

Re:Go command support for embedded static assets (files) by zabil on Friday July 24, 2020 @05:26AM (#23937452)
I maintain an open source project written in golang that's test runner with an html reporting plugin.

I can use this feature to bundle the report template, css, js, images file with the plugin to make download installation and use of the plugin much easier.

Re:Go command support for embedded static assets (files) by zelly on Thursday July 23, 2020 @08:57PM (#23934507)
Performance. No additional I/O at startup and guaranteed to be in memory.
Re:Go command support for embedded static assets (files) by jeffbee on Thursday July 23, 2020 @09:28PM (#23934721)
I don't know what platform you had in mind, but this isn't generally true for Linux. No part of a Linux executable is in memory except the page containing the main entry point, initially. You'd have to pre-fault the sections of interest and protect them with mlock to make sure they stay in memory. If you don't their cached pages may be dropped, which is essentially the same thing as swapping.

In short, these embedded assets are no more likely to be in memory than any other file-backed data. If you want to guarantee they are in memory, it is up to you to make that happen.

Re:Go command support for embedded static assets (files) by yencabulator on Friday July 24, 2020 @01:10PM (#23941938)
Even then, it avoids open, path traversal, read read read, close.

More important is avoiding having to answer the question "where are my assets".

Re:Go command support for embedded static assets (files) by pansa2 on Thursday July 23, 2020 @09:18PM (#23934662)
Aren’t executable files loaded into memory page-by-page, on demand? There’s no guarantee that their contents are in memory.
Re:Go command support for embedded static assets (files) by pdq on Thursday July 23, 2020 @09:40PM (#23934789)
Correct, it’s addressable in process memory space, but not guaranteed to be paged into memory until accessed.