How to parse JSON data without struct in Golang

In using Golang, we sometimes need to parse a JSON data without knowing or specifying a concrete type struct. We can do this by converting (json.Unmarshal) JSON data into an interface{}. We can then use it like a map. Accessing it like for example m[“username”].(string) func AddUserHandler(w http.ResponseWriter, r *http.Request) { log.Println(“Processing Register User”) var […]

Continue Reading…

Golang MongoDB sort number inside a string

// Get List func (z *DocumentTagService) GetDocumentTags() ([]models.DocumentTag, error) { z.DatabaseService.Connect() var o []models.DocumentTag err := (*z.DatabaseService.Db).C(z.Collection).Find(bson.M{}).Sort(“-$natural”, “-documentReference”).All(&o) return o, err } Result [ { “idDocumentTag”: “5b1390f29ebea41854dcc0dc”, “documenReference”: “MCTU/2018/16”, “company”: “MCTU” }, { “idDocumentTag”: “5b1390f09ebea41854dcc0db”, “documenReference”: “MCTU/2018/15”, “company”: “MCTU” }, { “idDocumentTag”: “5b1390d19ebea41854dcc0da”, “documenReference”: “MCTU/2018/14”, “company”: “MCTU” }, { “idDocumentTag”: “5b1390d09ebea41854dcc0d9”, “documenReference”: “MCTU/2018/13”, “company”: “MCTU” […]

Continue Reading…