Convert string to *uint64 in golang

ecem picture ecem · Mar 10, 2015 · Viewed 9.8k times · Source

Assume there is a string holding the address of an uint64 type variable, can we parse this address back to an *uint64?

For example:

i := uint64(23473824)
ip := &i
str := fmt.Sprintf("%v", ip)

u, _ := strconv.ParseUint(str, 0, 64)

u is uint64. How to get pointer out of this value?

Playground link: https://play.golang.org/p/1KXFQcozRk

Answer

It is as simple as:

number, err := strconv.ParseUint(string("90"), 10, 64)

then do some error checking, hope it helps.