Difference between make(map) and map{}

The Go Programming Language Specification Making slices, maps and channels The built-in function make takes a type T, which must be a slice, map or channel type, optionally followed by a type-specific list of expressions. It returns a value of type T (not *T). The memory is initialized as described in the section on initial … Read more

In golang, is it possible to get reflect.Type from the type itself, from name as string?

On 1, yes, kinda: var v1 reflect.Type = reflect.TypeOf((*t1)(nil)).Elem() fmt.Println(v1) // prints “main.t1” No instantiation needed. However, Go doesn’t have type literals, which is I think what you’re asking for. To get the runtime value of a type, you need to have a value of some sort. If you don’t want to or can’t create … Read more

How do I initialize a composed struct in Go?

Use nested composite literals to initialize a value in a single expression: child := Child{Base: Base{ID: id}, a: a, b: b} Go issue 9859 proposes a change to make composite literals consistent with field access for embedded types. This change will allow the Child{ ID: id, a: a, b: b } expression from the question. … Read more

How to stop the golang gc and trigger it manually?

Package documentation of runtime contains all the details you need: The GOGC variable sets the initial garbage collection target percentage. A collection is triggered when the ratio of freshly allocated data to live data remaining after the previous collection reaches this percentage. The default is GOGC=100. Setting GOGC=off disables the garbage collector entirely. The runtime/debug … Read more

Println vs Printf vs Print in Go

Printf – “Print Formatter” this function allows you to format numbers, variables and strings into the first string parameter you give it Print – “Print” This cannot format anything, it simply takes a string and print it Println – “Print Line” same thing as Print() however it will append a newline character \n at the … Read more

How do you set the application icon in golang?

You can use a tool like akavel/rsrc in order to generate a .syso file with specified resources embedded in .rsrc section, aimed for consumption by Go linker when building Win32 excecutables. See as an example the lxn/walk application, which embeds other metadata in its executable. rsrc [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico…]] -o FILE.syso -ico=””: comma-separated list … Read more

Setting up Route Not Found in Gin

What you’re looking for is the NoRoute handler. More precisely: r := gin.Default() r.NoRoute(func(c *gin.Context) { c.JSON(404, gin.H{“code”: “PAGE_NOT_FOUND”, “message”: “Page not found”}) })

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)