golang
Did any #Go developers need code to get a zero value of a struct but without knowing the layout of the struct itself?
The only thing I could come up with was:
func zero[T any](v T) T {
z := &v
zz := reflect.ValueOf(z).Elem()
zz.Set(reflect.Zero(reflect.TypeOf(v)))
return *z
}
And see here an example of usage: https://go.dev/play/p/Aqzc_nRzOcP
I needed it in order to get zero copies of random structs so I could test that some marshal/unmarshal functionality is a bijection.
Is this a decent way to do it? Are there alternatives?
One issue I'm noticing when learning Go is that the idiomatic nature of the language is making the learning process more difficult for me than C++ or C#.
With C++/C# you can focus on how to write code and then how to design code, but there is a very tight coupling of these concepts in Go that is taxing my brain and pretty much forcing me down the tutorial route, which I tend to struggle with compared to the language reference route.
Sigh. I can fully understand why #golang have given up trying to improve the language’s cluttered error handling syntax, but it’s still disappointing. https://go.dev/blog/error-syntax
I will die on this hill.
#GameDev #Unity #UnityEngine #Unreal #UnrealEngine #UE #GoLang #PostgreSQL
var _ TheInterface = (*TheImplementation)(nil)
#GoLang
How the @#$% does #Hugo (static website generator) work with Github? Hundreds of pages reference #github but I still can't find how that works. Almost every Hugo help site says "add this reference to [a? your?] github repo..." but don't explain what the heck is happening or why I need that... why do I need a github repo to have a website somewhere else?
Clearly I don't need it; I have a hugo site up and running, and at no point was github involved.... except nothing would work until I initalized (?) my hugo directory (or the executable? IDK) on my webhost's server using a git command. For some reason.
I seriously don't understand why (or, more importantly, how) Hugo needs github. Right now dozens or hundreds of help sites seem like they're telling me that I need to have a shrine to my cat in my neighbor's house or else my blender won't work.
Lots of references to using github submodules and plenty of people saying "No! You fool! Don't do that!" and other people saying "Ackshully you should make your website a github module." Then other sites (including Hugo's official site) saying I should make my website into a #go module somehow for some reason... and I can't do that unless I have a github repo somewhere? Which is also maybe a Go module? Yet more sites saying I don't need to do that if I use some fancy scripts to fool something (my Hugo installation? My github repo? IDK) into thinking my Hugo site is or has a github repo...
If anyone would like to explain this to me like I'm literally 12 years old I'm very open to this. Every help site I've seen for weeks just assumes I understand some basic things that I don't remotely understand, like what the connection is between Hugo and github, how important it is, how it works, etc.
Understanding that I already have a functioning Hugo site, but apparently still need a github repo (maybe?) to do anything more interesting with it.
I know I'm using Mastodon as tech support a lot lately, but honestly y'all are more helpful than most search engines for some things.