Skip to content

Instantly share code, notes, and snippets.

@BrianLeishman
Created April 16, 2018 22:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianLeishman/1720c3c3d47b799d5dd913cedea654c5 to your computer and use it in GitHub Desktop.
Save BrianLeishman/1720c3c3d47b799d5dd913cedea654c5 to your computer and use it in GitHub Desktop.
MySQL UDF written in Go (Golang) instead of C
package main
// #include <stdio.h>
// #include <sys/types.h>
// #include <sys/stat.h>
// #include <stdlib.h>
// #include <string.h>
// #include <mysql.h>
// #cgo CFLAGS: -D ENVIRONMENT=0 -I/usr/include/mysql -fno-omit-frame-pointer
import "C"
//export bid2_go_init
func bid2_go_init(initid *C.UDF_INIT, args *C.UDF_ARGS, message *C.char) C.my_bool {
return 0
}
//export bid2_go
func bid2_go(initid *C.UDF_INIT, args *C.UDF_ARGS, result *C.char, length *uint64, isNull *C.char, message *C.char) *C.char {
*length = 8
return C.CString("yeet fam")
}
func main() {}
@BrianLeishman
Copy link
Author

go build -buildmode=c-shared -o udf.so && cp udf.so /usr/lib/mysql/plugin/udf.so

@olomor
Copy link

olomor commented Apr 4, 2020

Many thanks bro!!! Saved my life!!!
Simple and direct... gotcha! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment