On Sat, Feb 16, 2013 at 5:19 PM, Tech163 <
tec...@sliceone.com> wrote:
> I understand that in this specific case I can just read /proc/version, etc,
> but I'm curious how char[] can be converted to string.
Use the CGO[1] provided helpers:
> A few special functions convert between Go and C types by making copies of the data. In pseudo-Go definitions:
>
> // Go string to C string
> // The C string is allocated in the C heap using malloc.
> // It is the caller's responsibility to arrange for it to be
> // freed, such as by calling C.free.
> func C.CString(string) *C.char
>
> // C string to Go string
> func C.GoString(*C.char) string
>
> // C string, length to Go string
> func C.GoStringN(*C.char, C.int) string
>
> // C pointer, length to Go []byte
> func C.GoBytes(unsafe.Pointer, C.int) []byte
[1]:
http://golang.org/cmd/cgo/
-j