Last active
September 10, 2021 21:17
-
-
Save quenbyako/9c6076d8a931d6959e81cf336d72806c to your computer and use it in GitHub Desktop.
Default extra.go template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// go has a lot of copy-paste code. most of the time you can't _just_ alias your code globally. extra.go file | |
// is standard template of frequently used aliases. | |
package somepkg | |
type null = struct{} | |
// any is just alias to interface{} for better looking code (like `x := []any{1,'2',"three"}` looks better | |
// than `x := []interface{}{...}`) | |
// | |
// NOTE: after go 1.18, use constraints, DON'T use this alias, it looks as weird, as any other part of this | |
// file | |
type any = interface{} | |
// incomparable is a zero-width, non-comparable type. Adding it to a struct | |
// makes that struct also non-comparable, and generally doesn't add | |
// any size (as long as it's first). | |
type incomparable [0]func() | |
func check(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} | |
// Embed this type into a struct, which mustn't be copied, | |
// so `go vet` gives a warning if this struct is copied. | |
// | |
// See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details. | |
// and also: https://stackoverflow.com/questions/52494458/nocopy-minimal-example | |
type noCopy struct{} | |
func (*noCopy) Lock() {} | |
func (*noCopy) Unlock() {} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment