Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
cruft
Oct 25, 2007

The built in fully capable performant multi-threaded HTTP/2 server is a real selling point for me and the work I do.

I guess everybody already knows Go is good at this, but I feel like I need to jump on the bandwagon here.

Adbot
ADBOT LOVES YOU

ErIog
Jul 11, 2001

:nsacloud:

Hughmoris posted:

For you Go'ers (or whatever you call yourselves...): do you use Go for any sort of data analytics / data analyst jobs? I keep seeing it pop up on those type of job postings, and can't tell if I'm missing a big chunk of the data sector or if they are just spitballing keywords for the job description.

I wrote many scientific research pipelines in Go at a previous job, a lot of which hinged on analytics for making sure everything was working how it was intended to work. Go was lacking a lot of high level statistical functions at the time, but the other language features made it a very good fit for the job of reliably gathering the information (or erroring properly when the data was busted) to do statistics on. There were some points at the very end of finalizing a paper we'd pass small pieces of the data to R, but if we had ever exposed R to all the data it would have fallen over instantly or never finished the analysis we wanted to do.

So in some ways Go is not the sexiest choice for doing that kind of work, but it is frequently one of the best tools for doing 99% of the job.

cruft posted:

The built in fully capable performant multi-threaded HTTP/2 server is a real selling point for me and the work I do.

I guess everybody already knows Go is good at this, but I feel like I need to jump on the bandwagon here.

I also made a lot of use of this, and I was always expecting to find a point where it fell over or it was somehow worse than the more common stacks. I never did. Every bottleneck I found in stress-testing my endpoints was either in the firewall, Linux itself, or the database/app. It always kept up and worked reliably.

The other benefit I found over other stacks is that layers of the stack just disappear when you use Go because those things are built-in. It becomes so much easier to debug problems.

ErIog fucked around with this message at 03:34 on Apr 17, 2022

Methanar
Sep 26, 2013

by the sex ghost
I discovered today that some internal tool that interacts with MAAS to provision hardware is actually poorly written and can't handle hardware profiles with > 2 disks. Also it's hardcoded to expect a satadom disk as your boot partition and our latest hardware shipment doesn't actually have one of those. Unfortunately, I need this to work 2 weeks ago as this is blocking a trainwreck, zero-notice, suddenly-my-problem project I have that is more than a week overdue now; because I've been dealing with constant interruptions with being an acting team lead and project manager for like 6 other people because the senior-most engineer of the team left and the real manager is ¯\_(ツ)_/¯

So I went down a rabbit hole of setting myself up with a dev environment for the tool, trying to understand how it works (the relevant code was literally in a file named `todo.go` to give you a sense of how half-written this thing is. The official MAAS api docs are god awful too.

Between all of that and the half-written api client this tool is using, it's wasted like 5 hours of my time to get set up and to make changes to provision all non-boot partition disks into one big LVM as a fix. Except it doesn't work. I ended up having to read the real MAAS server's unit tests to figure out what the gently caress it actually wanted as parameters for my create PV and create LV calls because the docs just don't tell you. I'm still having type errors I don't fully understand because my http client doesn't make any sense and finally threw my hands up in frustration for the night.

honestly I don't even know if making it all one big ext4 LVM is even a good idea, it might not be because we're running databases and elasticsearch on this eventually and ???

Overall pretty disappointed in myself right now for taking so long to still have not actually fixed the problem.

programming sucks. I hate reading about people who claim to do this for fun. It's not fun. Computers shouldn't exist.

Methanar fucked around with this message at 03:23 on Jun 21, 2022

cruft
Oct 25, 2007

Wow, I figured there were like zero people outside of Canonical who have ever read the MAAS code, but here we are. Sorry for your suffering, friend. We can all relate.

cruft
Oct 25, 2007

How come nobody told me Go has generics now?

Breaking Glass
Dec 15, 2021

They're pretty great. We used them to write a workflow system and it was a massive improvement to the prior implementation. The limitation that variadic arguments have to all be the same type is a little frustrating.

Pham Nuwen
Oct 30, 2010



Breaking Glass posted:

The limitation that variadic arguments have to all be the same type is a little frustrating.

I assume Russ Cox has a frustratingly thorough explanation for why this is the only correct choice.

Breaking Glass
Dec 15, 2021

I'm rusty on the proposal but I think it was cut from an implementation complexity standpoint rather than a design issue, but I don't totally remember.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
that's okay I'll just make them all interface{}

Methanar
Sep 26, 2013

by the sex ghost

Jabor posted:

that's okay I'll just make them all interface{}

actual lol for some reason

Breaking Glass
Dec 15, 2021

I guess it makes sense in that slices are also invariant. There'd have to be a runtime type assertion when accessing a generic slice, which you can just do yourself. It's still annoying for our thing's API, which ended up like:

Dep1(thing)
Dep2(thing, thing)
...

Still, having the compile time type safety did catch errors and make refactoring easier than it was without generics.

Anyway I wanna learn rust after like the last 8 years of my life being Go.

cruft
Oct 25, 2007

Can anybody help me understand what I need to do in order to make "go get github.com/dirtbags/moth/pkg/jsend" work outside of that source tree?

Like, I thought I was setting things up so other software could use that library, but apparently I'm missing something, because it tells me:

code:
go: module github.com/dirtbags/moth@upgrade found (v3.6.3+incompatible), but does not contain package github.com/dirtbags/moth/pkg/jsend
:confused:

Pham Nuwen
Oct 30, 2010



cruft posted:

Can anybody help me understand what I need to do in order to make "go get github.com/dirtbags/moth/pkg/jsend" work outside of that source tree?

Like, I thought I was setting things up so other software could use that library, but apparently I'm missing something, because it tells me:

code:
go: module github.com/dirtbags/moth@upgrade found (v3.6.3+incompatible), but does not contain package github.com/dirtbags/moth/pkg/jsend
:confused:

So you're trying to write software to use that jsend library? If you've done a `go mod init` in your code, you should be able to do `go get github.com/dirtbags/moth/pkg/jsend@v4.4.9` from within your code dir and it'll Just Work?

edit: oh, they've hosed up their versioning, poo poo, I forget how to fix this

edit 2: yeahhhh they haven't set up their go.mod correctly. They've tagged up through v4.x.x, which means go.mod should say "module github.com/dirtbags/moth/v4" but they didn't do that. See https://go.dev/doc/modules/major-version

edit 3: jsend is just a single small file so just copy it into your own tree, with correct attribution of course (these guys ALSO didn't bother to do copyright headers...)

Pham Nuwen fucked around with this message at 00:27 on Apr 12, 2023

cruft
Oct 25, 2007

Pham Nuwen posted:

So you're trying to write software to use that jsend library? If you've done a `go mod init` in your code, you should be able to do `go get github.com/dirtbags/moth/pkg/jsend@v4.4.9` from within your code dir and it'll Just Work?

edit: oh, they've hosed up their versioning, poo poo, I forget how to fix this

edit 2: yeahhhh they haven't set up their go.mod correctly. They've tagged up through v4.x.x, which means go.mod should say "module github.com/dirtbags/moth/v4" but they didn't do that. See https://go.dev/doc/modules/major-version

edit 3: jsend is just a single small file so just copy it into your own tree, with correct attribution of course (these guys ALSO didn't bother to do copyright headers...)

Dirtbags is me. I'm trying to fix this :) Your link has me down some sort of path, maybe there's a working import at the end of it.

Regarding copyright headers, what's the preferred way to denote that? I thought you just dropped LICENSE.md in the top level?

Pham Nuwen
Oct 30, 2010



cruft posted:

Dirtbags is me. I'm trying to fix this :) Your link has me down some sort of path, maybe there's a working import at the end of it.

Regarding copyright headers, what's the preferred way to denote that? I thought you just dropped LICENSE.md in the top level?

lol sorry for ripping on your code, good luck because while go mod is an improvement over what came before, wrestling it is also my least favorite part of the job.

As for headers, I suggest just doing what the Go code does:


code:

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

cruft
Oct 25, 2007

Pham Nuwen posted:

lol sorry for ripping on your code

Ha. No worries, everything you said is true: I'm too battle-scarred to think my code is some paragon of design or anything.

I appreciate the pointers! This will save me hours of head scratching and reading unrelated documents.

Judge Schnoopy
Nov 2, 2005

dont even TRY it, pal

cruft posted:

I appreciate the pointers!

These words should never be uttered in the Go thread

Pimblor
Sep 13, 2003
bob
Grimey Drawer
I've been writing Go now professionally since 2019. Mostly for boring automation type stuff, but I deeply appreciate being able to write code, have it hermetically sealed and just loving work every where on a fairly large fleet. Rust is there, but it's weird man. I hated Go with a passion when I first came to it, but I'm like a pod person now. I've been writing utility UI's in react served by gin and gorilla and stuffed into lambdas and chuffed is a word I'd use to describe deployment.

Startyde
Apr 19, 2007

come post with us, forever and ever and ever
Ebitengine is a game engine but makes for an amazing x-plat/x-arch UI middleware. For whatever reason I have an easier time with it than building web UIs to serve out.
Was inspired by some firm's use of it for dataviz, I forget who now though. :v:

ErIog
Jul 11, 2001

:nsacloud:

Pimblor posted:

I've been writing Go now professionally since 2019. Mostly for boring automation type stuff, but I deeply appreciate being able to write code, have it hermetically sealed and just loving work every where on a fairly large fleet. Rust is there, but it's weird man. I hated Go with a passion when I first came to it, but I'm like a pod person now. I've been writing utility UI's in react served by gin and gorilla and stuffed into lambdas and chuffed is a word I'd use to describe deployment.

The thing I think about constantly is whether or not Go got to where it is because other people were off bike-shedding Rust.

That said, I don't like the changes they made to modules and stuff past a certain point. They're not that hard to work around, though.

But yes, it does do the thing you're saying without the overhead of something like Java. It'll give you a set of swole binaries that never give you dependency issues anywhere.

mondomole
Jun 16, 2023

Startyde posted:

Ebitengine is a game engine but makes for an amazing x-plat/x-arch UI middleware. For whatever reason I have an easier time with it than building web UIs to serve out.
Was inspired by some firm's use of it for dataviz, I forget who now though. :v:

Have you seen https://github.com/rivo/tview? Not as good as a game engine for general graphics, but if you're looking to to upgrade a CLI from a bunch of flags to something more interactive, you get a pretty high impressiveness-to-effort ratio out of it.

30.5 Days
Nov 19, 2006
If you’re doing that direction you could also check our charm.sh

mondomole
Jun 16, 2023

30.5 Days posted:

If you’re doing that direction you could also check our charm.sh

Did you make that?? Those examples look incredible. I'm moved over to Rust and C++ for work these days but will recommend charm.sh for future gophers :)

30.5 Days
Nov 19, 2006
Naw I'm not that cool lol

mondomole
Jun 16, 2023

30.5 Days posted:

Naw I'm not that cool lol

Look we’re talking about terminal UIs in 2023. I think it’s safe to say nobody involved in this product or it’s discussion is cool :)

DARPA
Apr 24, 2005
We know what happens to people who stay in the middle of the road. They get run over.
When I first started Whispers of the dead it popped up some help text I accidentally closed. Anything to know besides run the dungeons highlighted with red stars?

edit: wrong thread.

DARPA fucked around with this message at 13:33 on Jun 21, 2023

cruft
Oct 25, 2007

DARPA posted:

When I first started Whispers of the dead it popped up some help text I accidentally closed. Anything to know besides run the dungeons highlighted with red stars?

edit: wrong thread.

Super curious about the answer now, op. Please keep us updated!

DARPA
Apr 24, 2005
We know what happens to people who stay in the middle of the road. They get run over.

cruft posted:

Super curious about the answer now, op. Please keep us updated!

Diablo 4 (video game) side quest system. It's alright. If you enjoyed previous diablos good chance you'd like this one.


As for Go, I put out a release on Friday and have this week off. Love how much more confident I am I won't be called with an issue compared to v1 of the software that is written in Python .

Qtotonibudinibudet
Nov 7, 2011



Omich poluyobok, skazhi ty narkoman? ya prosto tozhe gde to tam zhivu, mogli by vmeste uyobyvat' narkotiki
why the hell do "go mod get thing" and all the other various actions that leave go.mod untidy not just simply automatically run "go mod tidy"

what ridiculous scenario is there where you actually want to leave it untidy and why is accommodating _that_ the default instead of having a "leave everything hosed up, im doing SCIENCE" flag to disable automatic tidy on all the other commands

30.5 Days
Nov 19, 2006
Auto updating all my packages everytime I add one is generally not what I want

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I have zero experience with go but I was interested in installing a subsonic server https://github.com/sentriz/gonic, and had a question about the installation from source instructions which mention:
code:
go install go.senan.xyz/gonic/cmd/gonic@latest
I have no idea what this go.senan.xyz host is, and wasn't sure about the security aspect of installing something from it. It seems somewhat like a "curl ... | bash" type of install that I'm not a fan of. Is that sort of recommendation typical for a go app?

The route I ended up going with was:
code:
git clone https://github.com/sentriz/gonic
cd gonic
git checkout v0.15.2
go install cmd/gonic/gonic.go
Slightly better I think, but not perfect, of course. Is there a "go install ..." equivalent that can install it from github? How come I need to go through this go.senan.xyz host for it?

30.5 Days
Nov 19, 2006
I would try doing go install with GitHub instead of their custom path. Their path almost certainly just proxies through to GitHub. I don't know why people do that.

skul-gun
Dec 24, 2001
I got this account for Xmas.
Go modules are identified by url. From their go.mod, go.senan.xyz/gonic is the official name of the module. One reason to use your own domain is to not be tied down to one code hosting site. Another example of a project that uses its own domain is k8s.io/kubernetes

Checking out the git repo and compiling from there is totally fine. But I would point out that for the dependencies specified in gonic's go.mod, the go tool is effectively doing "go install ..." (actually go get) for each of those, and that's normal.

skul-gun fucked around with this message at 10:26 on Aug 31, 2023

cruft
Oct 25, 2007

fletcher posted:

I have no idea what this go.senan.xyz host is, and wasn't sure about the security aspect of installing something from it. It seems somewhat like a "curl ... | bash" type of install that I'm not a fan of. Is that sort of recommendation typical for a go app?

You'd rather compile and install source code you can't/won't review from GitHub than from the author's server? That is an interesting threat model.

Jamus
Feb 10, 2007
It’s still ‘curl | bash’ if the fetch command is ‘git’ and you compile and exec the binary yourself. Unless you deeply inspect the source code you’re just replacing a pipe with the file system.

I’m a little salty about this because it’s a difficult sell to package internal tools to engineers with “curl | sh” (from a trusted URL and verifiable source!) but nobody really thinks about their normal dependancy process with the same skepticism. I don’t quite understand it!

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

30.5 Days posted:

I would try doing go install with GitHub instead of their custom path. Their path almost certainly just proxies through to GitHub. I don't know why people do that.

I had tried a few attempts of doing this and couldn't figure it out, but maybe I just didn't have the right syntax. I don't have my bash history handy at the moment to see what I had attempted.


skul-gun posted:

Go modules are identified by url. From their go.mod, go.senan.xyz/gonic is the official name of the module. One reason to use your own domain is to not be tied down to one code hosting site. Another example of a project that uses its own domain is k8s.io/kubernetes

Checking out the git repo and compiling from there is totally fine. But I would point out that for the dependencies specified in gonic's go.mod, the go tool is effectively doing "go install ..." (actually go get) for each of those, and that's normal.

At least something like k8s.io has a larger group behind it, and it's way more popular so an issue would have better visibility!

I do see some other random hosts though in the dependencies list, so I suppose I would need to do something with "go mod replace" to deal with those?

Of course, it's not really feasible to go down through the whole dependency tree and review everything myself, so I could see how this whole exercise to limit my exposure to an issue is kinda futile.

cruft posted:

You'd rather compile and install source code you can't/won't review from GitHub than from the author's server? That is an interesting threat model.

Well, the way I see it is that at least the source code in github has the opportunity for me to review it, and it has more eyeballs on it in general.

That random server though, it could be compromised and there would potentially be a lot less visibility on it.

So at least installing from source (using the naive way described above) I would just have to worry about somebody re-tagging a compromised revision of the code. That's easy to handle though - I can just switch to a copy of the code that I've frozen at a point in time. Assuming I also do the same for all the dependencies, of course.

Jamus posted:

It’s still ‘curl | bash’ if the fetch command is ‘git’ and you compile and exec the binary yourself. Unless you deeply inspect the source code you’re just replacing a pipe with the file system.

I’m a little salty about this because it’s a difficult sell to package internal tools to engineers with “curl | sh” (from a trusted URL and verifiable source!) but nobody really thinks about their normal dependancy process with the same skepticism. I don’t quite understand it!


Totally true. The amount of trust you need to have when doing an "apt install <whatever>" is quite high...I guess I was just overall wondering if there's some simple things I can do to reduce exposure at least a little bit!

skul-gun
Dec 24, 2001
I got this account for Xmas.

fletcher posted:

So at least installing from source (using the naive way described above) I would just have to worry about somebody re-tagging a compromised revision of the code. That's easy to handle though - I can just switch to a copy of the code that I've frozen at a point in time. Assuming I also do the same for all the dependencies, of course.

Have a look at the gonic go.sum file. The go tool uses this file to verify the integrity of gonic's direct and indirect dependencies. Additionally, the go project runs a module proxy/mirror/checksum database, which the go tool uses by default.

So let's say one of gonic's dependencies secretly re-tags a release. If the go module proxy has already seen the module at that version, you'll get a checksum error. Even if the proxy hasn't seen the module before, there's still the checksums committed to the gonic repository. Here's an example I found on github of what a checksum error looks like: https://github.com/ameshkov/dnscrypt/issues/7

Breaking Glass
Dec 15, 2021

fletcher posted:

The route I ended up going with was:
code:
git clone https://github.com/sentriz/gonic
cd gonic
git checkout v0.15.2
go install cmd/gonic/gonic.go
Slightly better I think, but not perfect, of course. Is there a "go install ..." equivalent that can install it from github? How come I need to go through this go.senan.xyz host for it?

The equivalent of this command is

code:
go install https://go.senan.xyz/gonic/cmd/gonic@v0.15.2
Under the hood, cmd/go will first fetch https://go.senan.xyz/gonic/cmd/gonic?go-get=1 (note the query parameter). This tells the web host that the HTTPS client is looking for a go module. In the response, you see a couple headers:

code:
# curl -v "https://go.senan.xyz/gonic/cmd/gonic?go-get=1"
...
<meta name="go-import" content="go.senan.xyz/gonic git https://github.com/sentriz/gonic">
<meta name="go-source" content="go.senan.xyz/gonic https://github.com/sentriz/gonic https://github.com/sentriz/gonic/tree/master{/dir} https://github.com/sentriz/gonic/blob/master{/dir}/{file}#L{line}">
...
This is what instructs the go client that the hosted code should be fetched from github. (See https://pkg.go.dev/cmd/go#hdr-Remote_import_paths and adjacent code for details, if you're curious.)

fletcher posted:

Well, the way I see it is that at least the source code in github has the opportunity for me to review it, and it has more eyeballs on it in general.

That random server though, it could be compromised and there would potentially be a lot less visibility on it.

skul-gun is correct that by requesting go.senan.xyz/gonic/cmd/gonic@v0.15.2, you're guaranteed to get the same code that is in the checksum database maintained by the Go team at Google. This is documented here: https://go.dev/ref/mod#checksum-database.

The checksum database is probably the biggest killer feature for the language, and protects you against the exact kind of risk that you are worried about. It's also independently auditable. The module URL serves as the canonical identifier for that code, and you can verify that with your eyeballs, git client, and your local cache of installed modules on your machine located at # go env GOPATH.

I always install with a specific version tag when I don't absolutely trust the source. But @latest is really handy for things you do trust, like go install golang.org/dl/go1.21.0@latest.

One last note worth mentioning is that go install is as safe as git then compiling it can be, in terms of curl | bash. No code is evaluated during go compilation like it is by package managers for other languages, such as npm.

Edit:

You check out the checksum tree node yourself, too:

code:
# curl "https://sum.golang.org/lookup/go.senan.xyz/gonic@v0.15.2"
14508769
go.senan.xyz/gonic v0.15.2 h1:oNQmvtzykWIn1GSZe1WuZDrcMV4KAnYOhbb1kLtXjz4=
go.senan.xyz/gonic v0.15.2/go.mod h1:Ik4Z2JJ92Fn7kclsQ7J8Vn8RzFukOj2kkq0nDLTBILU=

go.sum database tree
19357738
0yxtX24hWJ8X8GMTBiz7BMltZmt45gzA7IWmSNLh2U0=

— sum.golang.org Az3grpurPxcRYohe88GqMor19nIMyKhChumxTqfggY1ORJTJGCTu2VQ9hZGaG8yQwpgI/fzFfT1DKZV86PBIM9tSLw4=
If anything about this version or any prior version changed, it would invalidate the tree, and cmd/go would refuse to install it. This tree is kept up to date via modules fetched through https://proxy.golang.org/.

Breaking Glass fucked around with this message at 22:01 on Aug 31, 2023

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
also note that unlike most build systems the go tool does not allow any arbitrary commands to run so it's not like it can run rm -rf ~ or whatever

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Thanks for all the great info! That's really cool they have the safeguards in place already with tracking the dependency checksums to mitigate the concerns.

Running arbitrary commands during the build was part of the concern, but the other part of it was the thing it's building doing something malicious when I go to execute whatever it built.

I learned a lot here, greatly appreciated and thank you!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply