structs-complex/main.go

package main

// #cgo CFLAGS: -g -Wall
/*
struct body {
  char *format;
  char *text;
};
struct page {
  char *title;
  struct body body;
};
*/
import "C"

import (
	"fmt"
	"github.com/davecgh/go-spew/spew"
)

type body struct {
	format string
	text   string
}

type page struct {
	title string
	body  body
}

func CCreate(p C.struct_page) {
	Create(page{
		title: C.GoString(p.title),
		body: body{
			format: C.GoString(p.body.format),
			text:   C.GoString(p.body.text),
		},
	})
}

func Create(p page) {
	fmt.Println("requested to create a page:")
	spew.Dump(p)
}

func main() {
	p := C.struct_page{
		title: C.CString("hello"),
		body: C.struct_body{
			format: C.CString("markdown"),
			text:   C.CString("hello world"),
		},
	}
	CCreate(p)
}