I am using firego to do operations on the firebase. I am unable to retrieve the auto generated unique ID after a successful push. I used the fllowing code:
adminData, err := dB.Child("Admins").Push(m)
if err != nil {
log.Println(err)
}
log.Println("Unique ID: ", adminData)
and it print:
https://myApp.firebaseio.com/Admins/-KddtEfpE3ys4cj0mYE-/.json
the variable adminData is of type *Firebase
but I need only -KddtEfpE3ys4cj0mYE-
as type String
How I can do this in Golang using firego?
firego does not expose this information, you can either create an issue to firego repository on github or modify the library yourself.
also there is a dirty way to split by /
character and get last but one element.
package main
import (
"fmt"
"strings"
)
func main() {
parts := strings.Split("https://myApp.firebaseio.com/Admins/-KddtEfpE3ys4cj0mYE-/.json", "/")
fmt.Println(parts[len(parts)-2]) // -KddtEfpE3ys4cj0mYE-
}
Though I would recommend you to open an issue to firego :)