How do I serve CSS and JS in Go

http.Handle(“https://stackoverflow.com/”, http.FileServer(http.Dir(“css/”))) Would serve your css directory at /. Of course you can serve whichever directory at whatever path you choose. You probably want to make sure that the static path isn’t in the way of other paths and use something like this. http.Handle(“/static/”, http.StripPrefix(“/static/”, http.FileServer(http.Dir(“static”)))) Placing both your js and css in the directory … Read more

Concisely deep copy a slice?

Not sure which solution is fastest without a benchmark, but an alternative is using the built in copy: cpy := make([]T, len(orig)) copy(cpy, orig) From the documentation: func copy(dst, src []Type) int The copy built-in function copies elements from a source slice into a destination slice. (As a special case, it also will copy bytes … Read more

How to parse non standard time format from json

That’s a case when you need to implement custom marshal and unmarshal functions. UnmarshalJSON(b []byte) error { … } MarshalJSON() ([]byte, error) { … } By following the example in the Golang documentation of json package you get something like: // First create a type alias type JsonBirthDate time.Time // Add that to your struct … Read more

not compatible with reflect.StructTag.Get

Remove the space after the comma before omitempty, then the error message will go away. bson:”password” json:”password,omitempty” (should be like this) In addition, this is a warning not an error. You should still be able to run your project.

How do you do UUID in Golangs Gorm?

For postgresql, here is what I did: go get github.com/google/uuid Use uuid.UUID (from “github.com/google/uuid”), as type, e.g ID uuid.UUID `gorm:”type:uuid;default:uuid_generate_v4()”` Add uuid-ossp extension for postgres database, e.g CREATE EXTENSION IF NOT EXISTS “uuid-ossp”; Then, when you call DB’s Create() method, the uuid is generated automatically. Update: pg14+ gen_random_uuid() (as mentioned in Doron Segal‘s comment) pg … Read more

cannot take the address of” and “cannot call pointer method on

The Vector3.Normalize() method has a pointer receiver, so in order to call this method, a pointer to Vector3 value is required (*Vector3). In your first example you store the return value of Vector3.Minus() in a variable, which will be of type Vector3. Variables in Go are addressable, and when you write diff.Normalize(), this is a … Read more

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