cgo is picky about the formatting: you need to keep the "C" import separate, and place the preamble comments immediately above:
package main
// #cgo LDFLAGS: -lX11
// #include <X11/Xlib.h>
import "C"
import (
"fmt"
)
func main() {
var dpy = C.XOpenDisplay(nil)
if dpy == nil {
panic("Can't open display")
}
fmt.Println("%ix%i", C.XDisplayWidth(dpy, 0), C.XDisplayHeight(dpy, 0));
}