Skip to content

Instantly share code, notes, and snippets.

@ymotongpoo
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save ymotongpoo/11f4392851543554cac3 to your computer and use it in GitHub Desktop.

Select an option

Save ymotongpoo/11f4392851543554cac3 to your computer and use it in GitHub Desktop.
Go1.5 c-shared test
#!/bin/bash
go build -buildmode=c-shared -o libgomain.so main.go
gcc main.c -o main ./libgomain.so
#include <stdio.h>
#include "libgomain.h"
int
main(int argc, char** argv) {
printf("start c-main\n");
fflush(stdout);
server();
return 0;
}
package main
import (
"C"
"log"
"net/http"
)
//export server
func server() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, Go c-shared lib"))
}
func init() {
log.Println("Go HTTP server is loaded")
}
func main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment